Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- $("#createLetter").on("click", CreateLetter);
- function CreateLetter() {
- $.ajax({
- type: "POST",
- url: "/Letters/CreateLetter",
- data: {
- EntityType: "@overview.EntityType",
- EntityId: @overview.EntityId,
- Recipient: $("#Recipient").val(),
- TemplatesLocation: $("#templatePath").val(),
- SaveAs: $("#saveAs").val()
- },
- async: false,
- success: openLetter
- });
- }
- function openLetter(data) {
- openFile(data);
- window.location.reload(false);
- }
- [ValidateInput(false)]
- [HttpPost]
- public JsonResult CreateLetter(CreateLetter input)
- {
- Recipient obj = logic.SplitRecipientInput(input.Recipient);
- input.RecipientId = obj.RecipientId;
- input.RecipientType = obj.Type;
- input.Username = Helpers.GetLoggedInUser();
- var x = logic.CreateLetter(input);
- if (x.Success == 1)
- {
- return Json(x.Data, JsonRequestBehavior.AllowGet);
- }
- else
- {
- return Json("Error", JsonRequestBehavior.AllowGet);
- }
- }
- public CreatedLetter CreateLetter(CreateLetter input)
- {
- CreatedLetter response = new CreatedLetter();
- Parameters.Add("TemplatePath", GetApiValue(input.TemplatesLocation));
- Parameters.Add("EntityType", GetApiValue(input.EntityType));
- Parameters.Add("EntityId", GetApiValue(input.EntityId));
- Parameters.Add("RecipientId", GetApiValue(input.RecipientId));
- Parameters.Add("RecipientType", GetApiValue(input.RecipientType));
- Parameters.Add("Username", GetApiValue(input.Username));
- Parameters.Add("SaveAs", GetApiValue(input.SaveAs));
- response = Api.WebRequest<CreatedLetter>("CreateLetters", Parameters, Method.POST) as CreatedLetter;
- return response;
- }
- [ActionName("CreateLetter")]
- [HttpPost]
- public ApiResponse CreateLetter(LetterCreateInput input)
- {
- try
- {
- LetterTemplateLogic logic = new LetterTemplateLogic();
- Random r = new Random();
- var randomId = r.Next(100000, 999999);
- string fileName = string.Format("{0} - {1}", randomId, input.SaveAs);
- input.SaveAs = fileName;
- // Get all objects for Letter
- List<object> objs = logic.TemplateObjectsRetriever(input.EntityId, input.EntityType, input.Username, randomId);
- objs.Add(logic.GetRecipient(input.RecipientId, input.RecipientType));
- // Get save location
- string saveLocation = logic.LetterLocationResolver(input.EntityId, input.EntityType);
- var data = logic.OpenAndUpdateTemplate(objs, input.TemplatePath, input.SaveAs, saveLocation, FileExtension);
- AttachmentInput letterAttachment = new AttachmentInput();
- letterAttachment.Id = input.EntityId;
- letterAttachment.FileTypeId = 1;
- letterAttachment.Path = data;
- letterAttachment.Username = input.Username;
- letterAttachment.Description = fileName;
- letterAttachment.EntityType = input.EntityType;
- logic.InsertLetterAttachment(letterAttachment);
- return ApiResponse.Return(data);
- }
- catch (Exception ex)
- {
- return ApiResponse.Error(ex);
- }
- }
Add Comment
Please, Sign In to add comment