public ActionResult Index(string Case = null, string Content = null) { ReceiveLetterManager receiveLetterManager = new ReceiveLetterManager(); IncomingLettersViewModel incomingLettersViewModel = new IncomingLettersViewModel { PageId = "IncomingShowAll" }; StringBuilder stb = new StringBuilder(); stb.Append(""); if (Case != null) { stb.Append($"Case == {Case} &&"); } if (Content != null) { stb.Append($"Content == {Content} &&"); } stb.Append("1==1"); incomingLettersViewModel.ListReciveLetters = receiveLetterManager.Read(stb.ToString(), "ParentReceiveLetter,ParentSendLetterOut").ToList(); return(View(incomingLettersViewModel)); }
public FileResult DownloadLetterContent(Guid id) { ReceiveLetterManager recieLetterManager = new ReceiveLetterManager(); ReceivedLetter receivedLetter = new ReceivedLetter(); receivedLetter = recieLetterManager.Read(id); byte[] file = receivedLetter?.LetterFileContent; if (file != null && file.Length > 0) { string fileName = id + ".pdf"; return(File(file, System.Net.Mime.MediaTypeNames.Application.Octet, fileName)); } return(null); }
//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(EditIncomingLettersViewModel editIncomingLettersViewModel) { ReceiveLetterManager receiveLetterManager = new ReceiveLetterManager(); ReceivedLetter oldLetter = receiveLetterManager.Read(editIncomingLettersViewModel.ReceivedLetter.Id); #region temp TempReceiveLetterManager tempReceiveLetterManager = new TempReceiveLetterManager(); //Get Letter before Edit ReceivedLetter receivedLetter = tempReceiveLetterManager.ReturnReceivedLetter(editIncomingLettersViewModel.ReceivedLetter.Id); if (receivedLetter == null) { throw new Exception("نامه مورد نظر یافت نگردید."); } TempReceivedLetter tempReceivedLetter = new TempReceivedLetter { User = receivedLetter.User, Sender = receivedLetter?.Sender ?? null, ParentType = receivedLetter.ParentType, AppendageContent = receivedLetter.AppendageContent, LetterFileContent = receivedLetter.LetterFileContent, ArchiveDateTime = receivedLetter.ArchiveDateTime, LetterDateTime = receivedLetter.LetterDateTime, ModifyDateTime = receivedLetter.LastModifyDateTime, Assortment = receivedLetter.Assortment, Cases = new List <Case>(), RowNumber = receivedLetter.RowNumber, Description = receivedLetter.Description, ReceivedLetter = receivedLetter, ParentSendLetterOutTemp = receivedLetter.ParentSendLetterOut, ParentReceiveLetter = receivedLetter.ParentReceiveLetter, TempReceiveLetterFiles = new List <TempReceiveLetterFile>(), TempReceiveAppendages = new List <TempReceiveAppendage>(), LetterFileAppendageContent = receivedLetter.LetterFileAppendageContent, Active = true }; //Temp Collection of Cases foreach (var item in receivedLetter.Cases) { tempReceivedLetter.Cases.Add(item); } //Copy files to temp foreach (var item in receivedLetter.ReceiveLetterFiles) { TempReceiveLetterFile newTempReceiveLetterFile = new TempReceiveLetterFile { File = item.File }; tempReceivedLetter.TempReceiveLetterFiles.Add(newTempReceiveLetterFile); } //Copy Appendages to temp foreach (var item in receivedLetter.Appendages) { TempReceiveAppendage newTempReceiveLetterFile = new TempReceiveAppendage { File = item.File }; tempReceivedLetter.TempReceiveAppendages.Add(newTempReceiveLetterFile); } tempReceiveLetterManager.Add(tempReceivedLetter); tempReceiveLetterManager.saveChanges(); #endregion oldLetter.Assortment = editIncomingLettersViewModel.ReceivedLetter.Assortment; //oldLetter.RowNumber = editIncomingLettersViewModel.ReceivedLetter.RowNumber; oldLetter.Description = editIncomingLettersViewModel.ReceivedLetter.Description; //oldLetter.ParentReceiveLetter = editIncomingLettersViewModel.ReceivedLetter.ParentReceiveLetter; if (!string.IsNullOrEmpty(editIncomingLettersViewModel.LetterDateTime)) { oldLetter.LetterDateTime = editIncomingLettersViewModel.LetterDateTime.toEnglishNumber().ToGeorgianDateTime(); } receiveLetterManager.UpdateReceiveLetterFiles(oldLetter, editIncomingLettersViewModel.FileUploadLetters, editIncomingLettersViewModel.FilesId); receiveLetterManager.UpdateReceiveLetterAppendages(oldLetter, editIncomingLettersViewModel.FileUploadAppendages, editIncomingLettersViewModel.AppendagesId); oldLetter.LastModifyDateTime = DateTime.Now; if (oldLetter.User.Id != new Guid(User.Identity.Name)) { receiveLetterManager.AddUser(oldLetter, new Guid(User.Identity.Name)); } //oldLetter.ParentReceiveLetter = editIncomingLettersViewModel.ParentReceiveletterId != null ? receiveLetterManager.Read((Guid)editIncomingLettersViewModel.ParentReceiveletterId) : null; if (editIncomingLettersViewModel.PersonGuid != Guid.Empty || editIncomingLettersViewModel.OrganizationGuid != Guid.Empty) { receiveLetterManager.EditSender(oldLetter, editIncomingLettersViewModel.OrganizationGuid, editIncomingLettersViewModel.PersonGuid, editIncomingLettersViewModel.PostGuid); } receiveLetterManager.EditCases(oldLetter, editIncomingLettersViewModel.CasesGuid); oldLetter.RowNumber = editIncomingLettersViewModel.RowNumber; oldLetter.ParentType = editIncomingLettersViewModel.ReceivedLetter.ParentType; //Set Parent Letter receiveLetterManager.SetParent(oldLetter, editIncomingLettersViewModel.ParentletterId); receiveLetterManager.GeneratePDF(oldLetter); receiveLetterManager.Update(oldLetter); receiveLetterManager.saveChanges(); return(RedirectToAction("Index")); }
public ActionResult Edit(Guid?ID) { isEdit = true; EditIncomingLettersViewModel editIncomingLettersViewModel = new EditIncomingLettersViewModel(); ReceiveLetterManager receiveLetterManager = new ReceiveLetterManager(); PostManager postManager = new PostManager(); PersonManager personManager = new PersonManager(); CaseManager caseManager = new CaseManager(); User currentUser = userManager.Read(new Guid(User.Identity.Name)); cUser = currentUser; if (ID != null && ID != Guid.Empty) { editIncomingLettersViewModel.ReceivedLetter = receiveLetterManager.Read((Guid)ID); if (editIncomingLettersViewModel.ReceivedLetter == null) { return(RedirectToAction("Index")); } } else { return(RedirectToAction("Index")); } //Selected Person and Organization and Post Logic if (editIncomingLettersViewModel.ReceivedLetter.Sender != null) { if (editIncomingLettersViewModel.ReceivedLetter.Sender.Organization != null) { editIncomingLettersViewModel.People = personManager.GetOrganizationPersons(editIncomingLettersViewModel.ReceivedLetter.Sender.Organization, editIncomingLettersViewModel.ReceivedLetter.Sender.Post?.Id ?? new Guid()); } else { editIncomingLettersViewModel.People = userManager.GetUserShowablePeopleList(currentUser); } //Fix problem of not showable but selected Person if (editIncomingLettersViewModel.ReceivedLetter.Sender.Person != null) { if (editIncomingLettersViewModel.People.All(x => x.Id != editIncomingLettersViewModel.ReceivedLetter.Sender.Person.Id)) { editIncomingLettersViewModel.People.Add(editIncomingLettersViewModel.ReceivedLetter.Sender.Person); } } } else { editIncomingLettersViewModel.People = userManager.GetUserShowablePeopleList(currentUser); } editIncomingLettersViewModel.OrganizationJson = getWhileLoopData(); editIncomingLettersViewModel.Cases = caseManager.Read(null); editIncomingLettersViewModel.Posts = postManager.Read(null); editIncomingLettersViewModel.LetterFiles = new List <FileViewModel>(); foreach (ReceiveLetterFile itemFile in editIncomingLettersViewModel.ReceivedLetter.ReceiveLetterFiles) { FileViewModel fileViewModel = new FileViewModel { Content = itemFile.File.Content.GetContentBase64(itemFile.File.ContentType), Id = itemFile.Id }; editIncomingLettersViewModel.LetterFiles.Add(fileViewModel); } editIncomingLettersViewModel.LetterAppendages = new List <FileViewModel>(); foreach (ReceiveAppendage itemFile in editIncomingLettersViewModel.ReceivedLetter.Appendages) { FileViewModel fileViewModel = new FileViewModel { Content = itemFile.File.Content.GetContentBase64(itemFile.File.ContentType), Id = itemFile.Id }; editIncomingLettersViewModel.LetterAppendages.Add(fileViewModel); } //Process Letter Parent //Set Parent Letter try { switch (editIncomingLettersViewModel.ReceivedLetter.ParentType) { case ParentType.Receive: var parent = receiveLetterManager.GetParent(editIncomingLettersViewModel.ReceivedLetter.Id); editIncomingLettersViewModel.ReceivedLetter.ParentReceiveLetter = parent; break; case ParentType.Send: var parent2 = receiveLetterManager.GetParentOut(editIncomingLettersViewModel.ReceivedLetter.Id); editIncomingLettersViewModel.ReceivedLetter.ParentSendLetterOut = parent2; break; default: break; } } catch { } //try //{ // var parent = receiveLetterManager.GetParent(editIncomingLettersViewModel.ReceivedLetter.Id); // editIncomingLettersViewModel.ParentRowNumber = parent.RowNumber; // editIncomingLettersViewModel.ReceivedLetter.ParentReceiveLetter = receiveLetterManager.Read(parent.Id); //} //catch //{ // editIncomingLettersViewModel.ParentRowNumber = ""; //} return(View(editIncomingLettersViewModel)); }