public FileResult Download(Guid id) { SendLetterManager sendLetterManager = new SendLetterManager(); SendLetter sendLetter = new SendLetter(); sendLetter = sendLetterManager.Read(id); byte[] file = sendLetter?.LetterFileContent; if (file != null && file.Length > 0) { string fileName = id + ".pdf"; return(File(file, System.Net.Mime.MediaTypeNames.Application.Octet, fileName)); } else { return(null); } }
//End Json Methods // GET: IncomingLetters public ActionResult Index(string Case = null, string Content = null) { OutgoingLettersViewModel outgoingLettersViewModel = new OutgoingLettersViewModel(); SendLetterManager sendLetterManager = new SendLetterManager(); outgoingLettersViewModel.PageId = "ShowOutgoingLetters"; StringBuilder stb = new StringBuilder(); stb.Append(""); if (Case != null) { stb.Append($"Case == {Case} &&"); } if (Content != null) { stb.Append($"Content == {Content} &&"); } stb.Append("1==1"); outgoingLettersViewModel.ListSendLetters = sendLetterManager.Read(stb.ToString(), "ParentSendLetter,ParentRecievedLetterOut").ToList(); return(View(outgoingLettersViewModel)); }
//private DatabaseContext context; // GET: AdvanceSearch public ActionResult Index(Guid?letterID, ParentType?letterType) { if (letterID != null && letterID != Guid.Empty) { SendLetterManager sendLetterManager = new SendLetterManager(); ReceiveLetterManager receiveLetterManager = new ReceiveLetterManager(); Tuple <List <ReceivedLetter>, List <SendLetter> > myTuple; switch (letterType) { case ParentType.Receive: //var sendLetterChildrens = sendLetterManager.GetChildItems((Guid) letterID, // new List<SendLetter>()); myTuple = receiveLetterManager.GetChildItems((Guid)letterID, new Tuple <List <ReceivedLetter>, List <SendLetter> >(new List <ReceivedLetter>(), new List <SendLetter>())); break; case ParentType.Send: myTuple = sendLetterManager.GetChildItems((Guid)letterID, new Tuple <List <ReceivedLetter>, List <SendLetter> >(new List <ReceivedLetter>(), new List <SendLetter>())); break; default: throw new ArgumentOutOfRangeException(nameof(letterType), letterType, null); } //Initialize letters who is not child of this item AdvanceSearchViewModel advanceSearchViewModel = new AdvanceSearchViewModel { ReceivedLetters = new List <ReceivedLetter>(), SendLetters = new List <SendLetter>() }; foreach (var item in receiveLetterManager.Read("1==1", "ParentReceiveLetter,ParentSendLetterOut").ToList()) { if (myTuple.Item1.All(x => x.Id != item.Id)) { advanceSearchViewModel.ReceivedLetters.Add(item); } } foreach (var item in sendLetterManager.Read("1==1", "ParentSendLetter,ParentReceivedLetterOut").ToList()) { if (myTuple.Item2.All(x => x.Id != item.Id)) { advanceSearchViewModel.SendLetters.Add(item); } } //AdvanceSearchViewModel advanceSearchViewModel = new AdvanceSearchViewModel //{ // SendLetters = sendLetterManager.Read(x => myTuple.Item2.All(y => y.Id != x.Id),null, "ParentSendLetterOut,ParentSendLetter").ToList(), // ReceivedLetters = receiveLetterManager.Read(x => myTuple.Item1.All(y => y.Id != x.Id),null, "ParentReceivedLetterOut,ParentReceiveLetter").ToList() //}; return(View(advanceSearchViewModel)); } else { SendLetterManager sendLetterManager = new SendLetterManager(); ReceiveLetterManager receiveLetterManager = new ReceiveLetterManager(); AdvanceSearchViewModel advanceSearchViewModel = new AdvanceSearchViewModel { PageId = "IncomingAndOutgoings", ReceivedLetters = receiveLetterManager.Read("1==1", "ParentSendLetterOut,ParentReceiveLetter").ToList(), SendLetters = sendLetterManager.Read("1==1", "ParentSendLetter,ParentReceivedLetterOut").ToList() }; return(View(advanceSearchViewModel)); } //} }
public ActionResult Edit(EditOutgoingLettersViewModel editOutgoingLettersViewModel) { SendLetterManager sendLetterManager = new SendLetterManager(); SendLetter oldLetter = sendLetterManager.Read(editOutgoingLettersViewModel.sendLetter.Id); #region temp TempSendLetterManager tempSendLetterManager = new TempSendLetterManager(); //Get Letter before Edit SendLetter sendletter = tempSendLetterManager.ReturnReceivedLetter(editOutgoingLettersViewModel.sendLetter.Id); if (sendletter == null) { throw new Exception("نامه مورد نظر یافت نگردید."); } TempSendLetter tempSendLetter = new TempSendLetter { User = sendletter.User, Recievers = sendletter?.Recievers ?? null, ParentType = sendletter.ParentType, AppendageContent = sendletter.AppendageContent, LetterFileContent = sendletter.LetterFileContent, ArchiveDateTime = sendletter.ArchiveDateTime, LetterDateTime = sendletter.LetterDateTime, ModifyDateTime = sendletter.LastModifyDateTime, Assortment = sendletter.Assortment, Cases = sendletter.Cases, RowNumber = sendletter.RowNumber, Description = sendletter.Description, SendLetter = sendletter, ParentReceivedLetterOutTemp = sendletter.ParentReceivedLetterOut, ParentSendLetter = sendletter.ParentSendLetter, TempSendLetterFiles = new List <TempSendLetterFile>(), Appendages = new List <TempSendAppendage>(), LetterFileAppendageContent = sendletter.LetterFileAppendageContent, Active = true, SenderEmployee = sendletter.SenderEmployee }; //Temp Collection of Cases //foreach (var item in sendletter.Cases) //{ // tempSendLetter.Cases.Add(item); //} //Copy files to temp foreach (var item in sendletter.sendLetterFiles) { TempSendLetterFile tempSendLetterFile = new TempSendLetterFile { File = item.File }; tempSendLetter.TempSendLetterFiles.Add(tempSendLetterFile); } //Copy Appendages to temp foreach (var item in sendletter.Appendages) { TempSendAppendage tempSendAppendage = new TempSendAppendage { File = item.File }; tempSendLetter.Appendages.Add(tempSendAppendage); } //Copy Recievers //foreach (var item in sendletter.Recievers) //{ // Reciever r = new Reciever(); // r.Id = item.Id; // r.Organization = item.Organization; // r.Person = item.Person; // r.Post = item.Post; //} tempSendLetterManager.Add(tempSendLetter); tempSendLetterManager.saveChanges(); #endregion //Set assortments oldLetter.Assortment = editOutgoingLettersViewModel.sendLetter.Assortment; //Set Description oldLetter.Description = editOutgoingLettersViewModel.sendLetter.Description; //Set letter content oldLetter.Body = editOutgoingLettersViewModel.sendLetter.Body; //Set Letter DateTime if (!string.IsNullOrEmpty(editOutgoingLettersViewModel.LetterDateTime)) { oldLetter.LetterDateTime = editOutgoingLettersViewModel.LetterDateTime.toEnglishNumber().ToGeorgianDateTime(); } oldLetter.LastModifyDateTime = DateTime.Now; if (oldLetter.User.Id != new Guid(User.Identity.Name)) { sendLetterManager.AddUser(oldLetter, new Guid(User.Identity.Name)); } //upload files sendLetterManager.UpdateSendLetterFiles(oldLetter, editOutgoingLettersViewModel.fileUploadLetters, editOutgoingLettersViewModel.FilesID); sendLetterManager.UpdateSendLetterAppendages(oldLetter, editOutgoingLettersViewModel.fileUploadAppendages, editOutgoingLettersViewModel.AppendagesID); oldLetter.ParentType = editOutgoingLettersViewModel.sendLetter.ParentType; //Set Parent Letter sendLetterManager.AddParent(oldLetter, editOutgoingLettersViewModel.ParentletterId); //update organization , post and person if (editOutgoingLettersViewModel.PersonGuid != Guid.Empty || editOutgoingLettersViewModel.OrganizationGuid != Guid.Empty) { sendLetterManager.EditReciever(oldLetter, editOutgoingLettersViewModel.OrganizationGuid, editOutgoingLettersViewModel.PersonGuid, editOutgoingLettersViewModel.PostGuid); } //update department , post and employee if (editOutgoingLettersViewModel.EmployeeGuid != Guid.Empty || editOutgoingLettersViewModel.DepartmentGuid != Guid.Empty) { sendLetterManager.EditSenderEmployee(oldLetter, editOutgoingLettersViewModel.DepartmentGuid, editOutgoingLettersViewModel.EmployeeGuid, editOutgoingLettersViewModel.DepartmentPostGuid); } //set rowNumber Logic oldLetter.RowNumber = editOutgoingLettersViewModel.autoRowNumber ? sendLetterManager.AutoRowNumber(oldLetter.SenderEmployee?.Department) : editOutgoingLettersViewModel.RowNumber; //Add cases sendLetterManager.EditCases(oldLetter, editOutgoingLettersViewModel.SelectedCasesGuid); //Start Processing Files and Appendages to Save them as pdf sendLetterManager.GeneratePDF(oldLetter, editOutgoingLettersViewModel.LetterTemplate); sendLetterManager.Update(oldLetter); sendLetterManager.saveChanges(); return(RedirectToAction("Index")); }
public ActionResult Edit(Guid?ID) { isEdit = true; EditOutgoingLettersViewModel editOutgoingLettersViewModel = new EditOutgoingLettersViewModel(); SendLetterManager sendLetterManager = new SendLetterManager(); PostManager postManager = new PostManager(); PersonManager personManager = new PersonManager(); CaseManager caseManager = new CaseManager(); EmployeeManager employeeManager = new EmployeeManager(); TemplateManager templateManager = new TemplateManager(); User currentUser = userManager.Read(new Guid(User.Identity.Name)); cUser = currentUser; if (ID != null && ID != Guid.Empty) { editOutgoingLettersViewModel.sendLetter = sendLetterManager.Read((Guid)ID); if (editOutgoingLettersViewModel.sendLetter == null) { return(RedirectToAction("Index")); } } else { return(RedirectToAction("Index")); } //Selected Person and Organization and Post Logic if (editOutgoingLettersViewModel.sendLetter.Recievers != null && editOutgoingLettersViewModel.sendLetter.Recievers.Count > 0 && editOutgoingLettersViewModel.sendLetter.Recievers.First() != null) { if (editOutgoingLettersViewModel.sendLetter.Recievers.First().Organization != null) { editOutgoingLettersViewModel.People = personManager.GetOrganizationPersons(editOutgoingLettersViewModel.sendLetter.Recievers.First().Organization, editOutgoingLettersViewModel.sendLetter.Recievers.First().Post?.Id ?? new Guid()); } else { editOutgoingLettersViewModel.People = userManager.GetUserShowablePeopleList(currentUser); } //Fix problem of not showable but selected Person if (editOutgoingLettersViewModel.sendLetter.Recievers.First().Person != null) { if (editOutgoingLettersViewModel.People.All(x => x.Id != editOutgoingLettersViewModel.sendLetter.Recievers.First().Person.Id)) { editOutgoingLettersViewModel.People.Add(editOutgoingLettersViewModel.sendLetter.Recievers.First().Person); } } } else { editOutgoingLettersViewModel.People = userManager.GetUserShowablePeopleList(currentUser); } editOutgoingLettersViewModel.OrganizationJson = getWhileLoopDataOrganization(); //Selected Employee and Department and Post Logic if (editOutgoingLettersViewModel.sendLetter.SenderEmployee != null) { if (editOutgoingLettersViewModel.sendLetter.SenderEmployee.Department != null) { editOutgoingLettersViewModel.Employees = employeeManager.GetDepartmentEmployees(editOutgoingLettersViewModel.sendLetter.SenderEmployee.Department, editOutgoingLettersViewModel.sendLetter.SenderEmployee.Post?.Id ?? new Guid()); } else { editOutgoingLettersViewModel.Employees = employeeManager.NoneDepartment(); } } else { editOutgoingLettersViewModel.Employees = employeeManager.NoneDepartment(); } editOutgoingLettersViewModel.DepartmentJson = getWhileLoopDataDepartment(); editOutgoingLettersViewModel.Cases = caseManager.Read(null); editOutgoingLettersViewModel.Posts = postManager.Read(null); editOutgoingLettersViewModel.Templates = templateManager.Read(null); editOutgoingLettersViewModel.LetterFiles = new List <FileViewModel>(); foreach (var itemFile in editOutgoingLettersViewModel.sendLetter.sendLetterFiles) { FileViewModel fileViewModel = new FileViewModel { Content = itemFile.File.Content.GetContentBase64(itemFile.File.ContentType), Id = itemFile.Id }; editOutgoingLettersViewModel.LetterFiles.Add(fileViewModel); } editOutgoingLettersViewModel.LetterAppendages = new List <FileViewModel>(); foreach (var itemFile in editOutgoingLettersViewModel.sendLetter.Appendages) { FileViewModel fileViewModel = new FileViewModel { Content = itemFile.File.Content.GetContentBase64(itemFile.File.ContentType), Id = itemFile.Id }; editOutgoingLettersViewModel.LetterAppendages.Add(fileViewModel); } //Process Letter Parent //Set Parent Letter try { switch (editOutgoingLettersViewModel.sendLetter.ParentType) { case ParentType.Send: var parent = sendLetterManager.GetParent(editOutgoingLettersViewModel.sendLetter.Id); editOutgoingLettersViewModel.sendLetter.ParentSendLetter = parent; break; case ParentType.Receive: var parent2 = sendLetterManager.GetParentOut(editOutgoingLettersViewModel.sendLetter.Id); editOutgoingLettersViewModel.sendLetter.ParentReceivedLetterOut = parent2; break; default: break; } } catch { } return(View(editOutgoingLettersViewModel)); }