public void Remove(ReceivedLetter Entity)
 {
     if (!Equals(DBC.ReceiveLetters.Remove(DBC.ReceiveLetters.Find(Entity.Id)), Entity))
     {
         throw new Exception(Entity.Id.ToString(), new Exception());
     }
 }
 public void Ubdate(ReceivedLetter Entity)
 {
     DBC.Entry(Entity).State = EntityState.Modified;
     if (DBC.SaveChanges() == 0)
     {
         throw new Exception(Entity.Id.ToString(), new Exception());
     }
 }
 public void Add(ReceivedLetter Entity)
 {
     DBC.ReceiveLetters.Add(Entity);
     if (DBC.SaveChanges() == 0)
     {
         throw new Exception(Entity.Id.ToString(), new Exception());
     }
 }
Пример #4
0
        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);
        }
Пример #5
0
        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"));
        }