Beispiel #1
0
        /*
         * public ActionResult Undex()
         * {
         *  return View();
         * }
         *
         * [HttpPost]
         * public ActionResult Undex(HttpPostedFileBase file)
         * {
         *  string fileName = string.Empty;
         *  string path = string.Empty;
         *
         *  try
         *  {
         #region Upload file
         *
         *      // Verify that the user selected a file
         *      if (file != null && file.ContentLength > 0)
         *      {
         *          // extract the extention
         *          var fileExtention = Path.GetExtension(file.FileName);
         *          // create filename
         *          //string fileName = response.ID + "." + fileExtention;
         *          // fileName = Path.GetFileName(file.FileName);
         *
         *          // Create a unique file name
         *          fileName = Guid.NewGuid() + fileExtention;
         *
         *          // Gettin current Year and Month
         *          PersianCalendar pc = new PersianCalendar();
         *          int year = pc.GetYear(DateTime.Now);
         *          int month = pc.GetMonth(DateTime.Now);
         *          string strMonth = month < 10 ? "0" + month.ToString() : month.ToString();
         *
         *          // Create File Path
         *          path = Path.Combine(Server.MapPath("~/data/" + year + "/" + strMonth), fileName);
         *          // Create reqired directried if not exist
         *          new FileInfo(path).Directory.Create();
         *
         *          // Uploading
         *          using (var fs = new FileStream(path, FileMode.Create))
         *          {
         *              var buffer = new byte[file.InputStream.Length];
         *              file.InputStream.Read(buffer, 0, buffer.Length);
         *
         *              fs.Write(buffer, 0, buffer.Length);
         *          }
         *      }
         *
         #endregion
         *  }
         *  catch (Exception ex)
         *  {
         *  }
         *
         #region Rename The file
         *
         *  // extract the extention
         *  var fileExtention2 = Path.GetExtension(path);
         *  // Get directory
         *  var directory = Path.GetDirectoryName(path);
         *  // create filename
         *  string fileName2 = directory + "/HOJJAT_" + Guid.NewGuid() + fileExtention2;
         *  // Rename file
         *  System.IO.File.Move(path, fileName2);
         *
         #endregion
         *
         *
         *  return RedirectToAction("Undex");
         * }
         */

        #endregion

        #region Update

        public JsonResult Document_Update(DocumentView document)
        {
            GeneralResponse response = new GeneralResponse();

            #region Access Check
            bool hasPermission = GetEmployee().IsGuaranteed("Document_Update");
            if (!hasPermission)
            {
                response.ErrorMessages.Add("AccessDenied");
                return(Json(response, JsonRequestBehavior.AllowGet));
            }
            #endregion

            EditDocumentRequest request = new EditDocumentRequest();

            request.ID = document.ID;
            request.ModifiedEmployeeID = GetEmployee().ID;
            request.DocumentName       = document.DocumentName;
            request.Photo      = document.Photo;
            request.Note       = document.Note;
            request.RowVersion = document.RowVersion;

            response = _documentService.EditDocument(request);

            return(Json(response, JsonRequestBehavior.AllowGet));
        }
Beispiel #2
0
        public HttpResponseMessage SaveFile(EditDocumentRequest postedData)
        {
            try
            {
                string htmlContent = postedData.getContent(); // Initialize with HTML markup of the edited document

                string saveFilePath = Path.Combine(globalConfiguration.GetEditorConfiguration().GetFilesDirectory(), postedData.GetGuid());
                if (File.Exists(saveFilePath))
                {
                    File.Delete(saveFilePath);
                }
                using (OutputHtmlDocument editedHtmlDoc = new OutputHtmlDocument(htmlContent, null))
                {
                    dynamic options = GetSaveOptions(saveFilePath);
                    if (options.GetType().Equals(typeof(WordProcessingSaveOptions)))
                    {
                        options.EnablePagination = true;
                    }
                    options.Password     = postedData.getPassword();
                    options.OutputFormat = GetSaveFormat(saveFilePath);
                    using (System.IO.FileStream outputStream = System.IO.File.Create(saveFilePath))
                    {
                        EditorHandler.ToDocument(editedHtmlDoc, outputStream, options);
                    }
                }
                LoadDocumentEntity loadDocumentEntity = LoadDocument(saveFilePath, postedData.getPassword());
                // return document description
                return(Request.CreateResponse(HttpStatusCode.OK, loadDocumentEntity));
            }
            catch (System.Exception ex)
            {
                // set exception message
                return(Request.CreateResponse(HttpStatusCode.Forbidden, new Resources().GenerateException(ex, postedData.getPassword())));
            }
        }
        public HttpResponseMessage SaveFile(EditDocumentRequest postedData)
        {
            try
            {
                string htmlContent  = postedData.getContent(); // Initialize with HTML markup of the edited document
                string guid         = postedData.GetGuid();
                string password     = postedData.getPassword();
                string saveFilePath = Path.Combine(globalConfiguration.GetEditorConfiguration().GetFilesDirectory(), guid);
                string tempFilename = Path.GetFileNameWithoutExtension(saveFilePath) + "_tmp";
                string tempPath     = Path.Combine(Path.GetDirectoryName(saveFilePath), tempFilename + Path.GetExtension(saveFilePath));

                ILoadOptions loadOptions = GetLoadOptions(guid);
                if (loadOptions != null)
                {
                    loadOptions.Password = password;
                }

                // Instantiate Editor object by loading the input file
                using (GroupDocs.Editor.Editor editor = new GroupDocs.Editor.Editor(guid, delegate { return(loadOptions); }))
                {
                    EditableDocument htmlContentDoc = EditableDocument.FromMarkup(htmlContent, null);
                    dynamic          saveOptions    = GetSaveOptions(guid);

                    if (!(saveOptions is TextSaveOptions))
                    {
                        saveOptions.Password = password;
                    }

                    if (saveOptions is WordProcessingSaveOptions)
                    {
                        saveOptions.EnablePagination = true;
                    }

                    using (FileStream outputStream = File.Create(tempPath))
                    {
                        editor.Save(htmlContentDoc, outputStream, saveOptions);
                    }
                }

                if (File.Exists(saveFilePath))
                {
                    File.Delete(saveFilePath);
                }

                File.Move(tempPath, saveFilePath);

                LoadDocumentEntity loadDocumentEntity = LoadDocument(saveFilePath, password);

                // return document description
                return(Request.CreateResponse(HttpStatusCode.OK, loadDocumentEntity));
            }
            catch (Exception ex)
            {
                // set exception message
                return(Request.CreateResponse(HttpStatusCode.InternalServerError, new Resources().GenerateException(ex, postedData.getPassword())));
            }
        }
        public async Task <IActionResult> EditOther(
            [FromHeader] Guid personUniqueId,
            [FromQuery] string uniqueId,
            [FromBody] EditDocumentRequest <OtherDocumentDetail> model,
            [FromServices] DocumentsManager manager)
        {
            var documentId = await manager.EditDocumentAsync(User.Identity.Name, personUniqueId, uniqueId, model);

            return(Json(new ApiResponse <string>(documentId)));
        }
        public HttpResponseMessage CreateFile(EditDocumentRequest postedData)
        {
            try
            {
                string htmlContent  = postedData.getContent();
                string guid         = postedData.GetGuid();
                string saveFilePath = Path.Combine(globalConfiguration.GetEditorConfiguration().GetFilesDirectory(), guid);
                string tempFilename = Path.GetFileNameWithoutExtension(saveFilePath) + "_tmp";
                string tempPath     = Path.Combine(Path.GetDirectoryName(saveFilePath), tempFilename + Path.GetExtension(saveFilePath));

                File.Create(saveFilePath).Dispose();

                using (EditableDocument newFile = EditableDocument.FromMarkup(htmlContent, null))
                {
                    using (GroupDocs.Editor.Editor editor = new GroupDocs.Editor.Editor(saveFilePath))
                    {
                        dynamic saveOptions = this.GetSaveOptions(saveFilePath);
                        if (saveOptions is WordProcessingSaveOptions)
                        {
                            // TODO: saveOptions.EnablePagination = true here leads to exception
                        }

                        using (FileStream outputStream = File.Create(tempPath))
                        {
                            editor.Save(newFile, outputStream, saveOptions);
                        }
                    }
                }

                if (File.Exists(saveFilePath))
                {
                    File.Delete(saveFilePath);
                }

                File.Move(tempPath, saveFilePath);

                LoadDocumentEntity loadDocumentEntity = LoadDocument(saveFilePath, "");

                // return document description
                return(Request.CreateResponse(HttpStatusCode.OK, loadDocumentEntity));
            }
            catch (Exception ex)
            {
                // set exception message
                return(Request.CreateResponse(HttpStatusCode.InternalServerError, new Resources().GenerateException(ex, postedData.getPassword())));
            }
        }
        public ConfirmationResponse Execute(EditDocumentRequest request)
        {
            request.ThrowExceptionIfInvalid();

            var entity = _documentRepository.Read(request.Id);

            entity.Name    = request.Name;
            entity.Content = request.Content;
            entity.Links   = request.Links;

            _documentRepository.Update(entity);

            return(new ConfirmationResponse("Document updated successfully.")
            {
                Id = entity.Id,
            });
        }
Beispiel #7
0
        public Document Map(EditDocumentRequest request)
        {
            if (request == null)
            {
                return(null);
            }

            Document document = new Document
            {
                Id = request.Id,
                CompanyTextDocument = request.CompanyTextDocument,
                CompanyTextDelivery = request.CompanyTextDelivery,
                CompanyTextInvoice  = request.CompanyTextInvoice,
                Number             = request.Number,
                DocumentType       = request.DocumentType,
                SubType            = request.SubType,
                TypeName           = request.TypeName,
                ValueBias          = request.ValueBias,
                Status             = request.Status,
                PrintDate          = request.PrintDate,
                ReminderDate       = request.ReminderDate,
                PrintCount         = request.PrintCount,
                NetPriceSum        = request.NetPriceSum,
                PriceGross         = request.PriceGross,
                IsArchived         = request.IsArchived,
                TextStartId        = request.TextStartId,
                TextHeadId         = request.TextHeadId,
                TextPaymentTermsId = request.TextPaymentTermsId,
                TextDeliveryId     = request.TextDeliveryId,
                TextEndId          = request.TextEndId,
                DocumentPersonId   = request.DocumentPersonId,
                DocumentCompanyId  = request.DocumentCompanyId,
                DeliveryPersonId   = request.DeliveryPersonId,
                DeliveryCompanyId  = request.DeliveryCompanyId,
                InvoicePersonId    = request.InvoicePersonId,
                InvoiceCompanyId   = request.InvoiceCompanyId,
            };

            return(document);
        }
Beispiel #8
0
        public async Task <DocumentResponse> EditDocumentAsync(EditDocumentRequest request)
        {
            Document existingRecord = await _documentRespository.GetAsync(request.Id);

            if (existingRecord == null)
            {
                throw new ArgumentException($"Entity with {request.Id} is not present");
            }

            if (request.TextStartId != null)
            {
                FAGText existingTextStart = await _fagTextRespository.GetAsync((Guid)request.TextStartId);

                if (existingTextStart == null)
                {
                    throw new NotFoundException($"TextStart with {request.TextStartId} is not present");
                }
            }

            if (request.TextHeadId != null)
            {
                FAGText existingTextHead = await _fagTextRespository.GetAsync((Guid)request.TextHeadId);

                if (existingTextHead == null)
                {
                    throw new NotFoundException($"TextHead with {request.TextHeadId} is not present");
                }
            }

            if (request.TextPaymentTermsId != null)
            {
                FAGText existingTextPaymentTerms = await _fagTextRespository.GetAsync((Guid)request.TextPaymentTermsId);

                if (existingTextPaymentTerms == null)
                {
                    throw new NotFoundException($"TextPaymentTerms with {request.TextPaymentTermsId} is not present");
                }
            }

            if (request.TextDeliveryId != null)
            {
                FAGText existingTextDelivery = await _fagTextRespository.GetAsync((Guid)request.TextDeliveryId);

                if (existingTextDelivery == null)
                {
                    throw new NotFoundException($"TextDelivery with {request.TextDeliveryId} is not present");
                }
            }

            if (request.TextEndId != null)
            {
                FAGText existingTextEnd = await _fagTextRespository.GetAsync((Guid)request.TextEndId);

                if (existingTextEnd == null)
                {
                    throw new NotFoundException($"TextEnd with {request.TextEndId} is not present");
                }
            }

            if (request.DocumentPersonId != null)
            {
                Person existingDocumentPerson = await _personRespository.GetAsync((Guid)request.DocumentPersonId);

                if (existingDocumentPerson == null)
                {
                    throw new NotFoundException($"DocumentPerson with {request.DocumentPersonId} is not present");
                }
            }

            if (request.DocumentCompanyId != null)
            {
                Company existingDocumentCompany = await _addressRespository.GetAsync((Guid)request.DocumentCompanyId);

                if (existingDocumentCompany == null)
                {
                    throw new NotFoundException($"DocumentCompany with {request.DocumentCompanyId} is not present");
                }
            }

            if (request.DeliveryPersonId != null)
            {
                Person existingDeliveryPerson = await _personRespository.GetAsync((Guid)request.DeliveryPersonId);

                if (existingDeliveryPerson == null)
                {
                    throw new NotFoundException($"DeliveryPerson with {request.DeliveryPersonId} is not present");
                }
            }

            if (request.DeliveryCompanyId != null)
            {
                Company existingDeliveryCompany = await _addressRespository.GetAsync((Guid)request.DeliveryCompanyId);

                if (existingDeliveryCompany == null)
                {
                    throw new NotFoundException($"DeliveryCompany with {request.DeliveryCompanyId} is not present");
                }
            }

            if (request.InvoicePersonId != null)
            {
                Person existingInvoicePerson = await _personRespository.GetAsync((Guid)request.InvoicePersonId);

                if (existingInvoicePerson == null)
                {
                    throw new NotFoundException($"InvoicePerson with {request.InvoicePersonId} is not present");
                }
            }

            if (request.InvoiceCompanyId != null)
            {
                Company existingInvoiceCompany = await _addressRespository.GetAsync((Guid)request.InvoiceCompanyId);

                if (existingInvoiceCompany == null)
                {
                    throw new NotFoundException($"InvoiceCompany with {request.InvoiceCompanyId} is not present");
                }
            }

            Document entity = _documentMapper.Map(request);
            Document result = _documentRespository.Update(entity);

            int modifiedRecords = await _documentRespository.UnitOfWork.SaveChangesAsync();

            _logger.LogInformation(Logging.Events.Edit, Messages.NumberOfRecordAffected_modifiedRecords, modifiedRecords);
            _logger.LogInformation(Logging.Events.Edit, Messages.ChangesApplied_id, result?.Id);

            return(_documentMapper.Map(result));
        }
Beispiel #9
0
        public GeneralResponse EditDocument(EditDocumentRequest request)
        {
            GeneralResponse response = new GeneralResponse();
            Document        document = new Document();

            document = _documentRepository.FindBy(request.ID);

            if (document != null)
            {
                try
                {
                    document.ModifiedDate     = PersianDateTime.Now;
                    document.ModifiedEmployee = _employeeRepository.FindBy(request.ModifiedEmployeeID);
                    if (request.DocumentName != null)
                    {
                        document.DocumentName = request.DocumentName;
                    }
                    if (request.ImageType != null)
                    {
                        document.ImageType = request.ImageType;
                    }
                    if (request.Photo != null)
                    {
                        document.Photo = request.Photo;
                    }
                    if (request.Note != null)
                    {
                        document.Note = request.Note;
                    }

                    if (document.RowVersion != request.RowVersion)
                    {
                        response.ErrorMessages.Add("EditConcurrencyKey");
                        return(response);
                    }
                    else
                    {
                        document.RowVersion += 1;
                    }

                    if (document.GetBrokenRules().Count() > 0)
                    {
                        foreach (BusinessRule businessRule in document.GetBrokenRules())
                        {
                            response.ErrorMessages.Add(businessRule.Rule);
                        }

                        return(response);
                    }

                    _documentRepository.Save(document);
                    _uow.Commit();

                    ////response.success = true;
                }
                catch (Exception ex)
                {
                    response.ErrorMessages.Add(ex.Message);
                }
            }
            else
            {
                response.ErrorMessages.Add("NoItemToEditKey");
            }
            return(response);
        }