Пример #1
0
        public Response DeleteAttachment([FromBody] AttachmentsModel attachmentsModel)
        {
            Response ans = null;

            try
            {
                if (ValidateSecurityAPI())
                {
                    ans = AttachmentsModel.DeleteAttachment(attachmentsModel);
                }
                else
                {
                    ans = new Response()
                    {
                        IsSuccessful = false, ResponseMessage = AppManagement.MSG_API_Validation_Failure
                    };
                }
            }
            catch (Exception ex)
            {
                ans = new Response()
                {
                    IsSuccessful = false, ResponseMessage = AppManagement.MSG_GenericExceptionError
                };
            }
            return(ans);
        }
Пример #2
0
        /// <summary>
        /// Adds the specified entity.
        /// </summary>
        /// <param name="entity">The entity.</param>
        /// <returns></returns>
        public AttachmentsModel Add(AttachmentsModel entity, string userEmail)
        {
            try
            {
                var         user        = LoggedInUser(userEmail);
                Attachments attachments = new Attachments()
                {
                    AccountId    = entity.AccountId,
                    AttachmentId = entity.AttachmentId,
                    CreationDate = DateTime.Now,
                    DeletedOn    = entity.DeletionDate,
                    DownloadUrl  = entity.DownloadUrl,
                    ExpiriedOn   = entity.ExpiryDate,
                    PurgedOn     = entity.ExpiryDate.AddDays(3),
                    Name         = entity.Name,
                    TotalSize    = entity.TotalSize,
                    Status       = entity.Status,
                    UserId       = user.Id
                };

                m_AttachmentRepository.Add(attachments);
                entity.AttachmentId = attachments.AttachmentId;
                entity.DownloadUrl  = attachments.DownloadUrl + "/" + attachments.AttachmentId;

                this.m_LogService.LogActivity((int)LogsActivityType.FileUpload, "File Uploaded by User" + user.FirstName + " " + user.LastName + "", (int)attachments.AttachmentId, "Attachment", user.Id);


                return(entity);
            }
            catch (Exception ex)
            {
                var message = string.Format("{0} {1} {2}", ex.InnerException == null ? ex.Message : ex.InnerException.Message, Environment.NewLine, ex.StackTrace);
                throw new Exception(message);
            }
        }
Пример #3
0
        public ResponseAttachmentsList GetAllAttachments(string identification)
        {
            ResponseAttachmentsList ans = null;

            try
            {
                if (ValidateSecurityAPI())
                {
                    ans = AttachmentsModel.GetAllAttachments(identification);
                }
                else
                {
                    ans = new ResponseAttachmentsList()
                    {
                        IsSuccessful = false, ResponseMessage = AppManagement.MSG_API_Validation_Failure
                    };
                }
            }
            catch (Exception ex)
            {
                ans = new ResponseAttachmentsList()
                {
                    IsSuccessful = false, ResponseMessage = AppManagement.MSG_GenericExceptionError
                };
            }

            return(ans);
        }
Пример #4
0
        public async Task <IActionResult> ListagemImagens(int produtoId)
        {
            if (produtoId == null)
            {
                return(NotFound());
            }
            string local = @"https://localhost:5001/";

            var attachmentsList = new List <AttachmentsModel>();

            var listaImagensProduto = _context.ImagensProduto.Where(p => p.ProdutoId == produtoId).ToList();

            foreach (var item in listaImagensProduto)
            {
                AttachmentsModel imagemProduto = new AttachmentsModel();

                imagemProduto.AttachmentID = item.ImagemProdutoId;
                imagemProduto.FileName     = item.ImagemUrl;
                imagemProduto.Path         = item.ImagemUrl;
                attachmentsList.Add(imagemProduto);
            }


            return(Json(new { Data = attachmentsList }));
            //return (IActionResult)listaImagensProdutoEspecifico;
        }
Пример #5
0
        public DocumentRetrieval OpenFileAttachment(int attachmentId)
        {
            DocumentRetrieval doc        = new DocumentRetrieval();
            DocumentModel     document   = _context.Documents.Where(p => p.FK_Attachment_Id == attachmentId).Single();
            AttachmentsModel  attachment = _context.Attachments.First(p => p.Id == attachmentId);

            doc.DocData  = Convert.FromBase64String(document.DocumentData);
            doc.DocType  = attachment.FileType;
            doc.FileName = attachment.FileName;
            return(doc);
        }
Пример #6
0
        public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "text/plain";
            string docName = context.Request.Files[0].FileName;

            string fileName     = DateTime.Now.ToFileTime() + Path.GetExtension(docName);
            string fkGuid       = context.Request.Form["fkGuid"];  //文档所属的业务主键标识
            string docType      = context.Request.Form["docType"]; //文档类型
            string relativePath = string.Empty;

            string sFileName = GenerateFileName(fileName);

            string sFilePath = CreateDirectory("", ref relativePath);

            HttpPostedFile hpf = context.Request.Files[0];

            AttachmentsModel attModel = new AttachmentsModel();

            UserModel userModel = (UserModel)N_Bers.Business.Core.Public.User_Info;

            attModel.CreateBy   = userModel.id;
            attModel.CreateUser = userModel.nickname;
            attModel.CreateOn   = DateTime.Now;
            attModel.DocName    = docName;
            attModel.FileName   = sFileName;
            attModel.FkGUID     = Convert.ToInt32(fkGuid);
            attModel.DocType    = docType;

            attModel.Location = relativePath;
            attModel.Filesize = hpf.ContentLength.ToString();

            try
            {
                hpf.SaveAs(Path.Combine(sFilePath, sFileName));
                attModel.Insert();
            }
            catch (Exception ex)
            {
                throw ex;
            }
            string fileRelativePath = Path.Combine(relativePath, sFileName);
            var    fileResponse     = new {
                DocName  = attModel.DocName,
                FielSize = attModel.Filesize,
                Path     = Path.Combine(relativePath, sFileName),
                CreateBy = attModel.CreateUser,
                Ext      = Path.GetExtension(docName),
            };

            context.Response.Clear();
            context.Response.Write(JsonExtensions.ToJson(fileResponse));
            context.Response.End();
        }
Пример #7
0
        public IActionResult AttachmentsDialog(AttachmentsModel model, DialogModel dm)
        {
            if (!Arguments.HasValue(model.EntityId, model.ObjectId))
            {
                return(JError(T["parameter_error"]));
            }
            model.EntityMetaData     = _entityFinder.FindByName("attachment");
            model.AttributeMetaDatas = _attributeFinder.FindByEntityId(model.EntityMetaData.EntityId);
            var result = _attachmentFinder.QueryPaged(model.Page, model.PageSize, model.EntityId, model.ObjectId);

            model.Items             = result.Items;
            model.TotalItems        = result.TotalItems;
            ViewData["DialogModel"] = dm;
            return(View(model));
        }
Пример #8
0
 public IActionResult Post([FromBody] AttachmentsModel entity)
 {
     try
     {
         if (ModelState.IsValid)
         {
             var UserEmail = User.Claims.Where(a => a.Type == ClaimTypes.Email).Select(a => a.Value).FirstOrDefault();;
             var result    = this.m_AttachmentsService.Add(entity, UserEmail, "Web");
             return(new OkObjectResult(result));
         }
         return(new BadRequestObjectResult(ModelState));
     }
     catch (Exception ex)
     {
         return(new BadRequestObjectResult(ex));
     }
 }
Пример #9
0
 public IActionResult Post([FromBody] AttachmentsModel entity)
 {
     try
     {
         if (ModelState.IsValid)
         {
             var UserEmail = User.Identity.Name;
             var result    = this.m_AttachmentsService.Add(entity, UserEmail);
             return(new OkObjectResult(result));
         }
         return(new BadRequestObjectResult(ModelState));
     }
     catch (Exception ex)
     {
         return(new BadRequestObjectResult(ex));
     }
 }
Пример #10
0
        public ActionResult Save(AttachmentsModel model)
        {
            var item = model.CloneToModel <AttachmentsModel, Attachments>();

            if (model.Id == 0)
            {
                var res = _AttachmentsRepository.Insert(item);
                return(new ActionResult()
                {
                    Success = res
                });
            }
            else
            {
                var res = _AttachmentsRepository.Update(item);
                return(new ActionResult()
                {
                    Success = res
                });
            }
        }
Пример #11
0
 public async Task <IJsonOperationResult <AttachmentsModel> > SendAttachmentsAsync(
     long accountNumber,
     Guid citationId,
     AttachmentsModel attachment) =>
 await _apiManager.PostAsync <AttachmentsModel, AttachmentsModel>($"{ApiConstants.API_VERSION_PREFIX}{accountNumber}/Citations/{citationId}/Attachment", attachment);
Пример #12
0
        public ActionResult UploadFile()
        {
            try
            {
                var file     = Request.Form.Files[0];
                var modelStr = Request.Form["model"];



                string folderName  = "Upload";
                string webRootPath = _hostingEnvironment.ContentRootPath;
                string newPath     = string.IsNullOrWhiteSpace(Constant.UploadFolder) ? Path.Combine(webRootPath, folderName) : Constant.UploadFolder;
                if (!Directory.Exists(newPath))
                {
                    Directory.CreateDirectory(newPath);
                }
                if (file.Length > 0)
                {
                    if (string.IsNullOrEmpty(modelStr))
                    {
                        AttachmentsModel model = new AttachmentsModel()
                        {
                            FileName    = file.FileName,
                            ContentType = file.ContentType,
                            CreatedDate = DateTime.Now,
                            FilePath    = Path.Combine(newPath, Guid.NewGuid() + "." + Path.GetExtension(file.FileName))
                        };
                        string fileName = file.FileName;
                        string fullPath = model.FilePath;
                        using (var stream = new FileStream(fullPath, FileMode.Create))
                        {
                            file.CopyTo(stream);
                        }

                        return(Json(new ResultBase <AttachmentsModel>()
                        {
                            success = true, data = model
                        }));
                    }
                    else
                    {
                        var model = JsonConvert.DeserializeObject <AttachmentConfigModel>(modelStr);
                        if (!Directory.Exists(model.SavePath))
                        {
                            return(Json(new ResultBase <AttachmentsModel>()
                            {
                                success = false, message = "Thư mục không tồn tại."
                            }));
                        }
                        else
                        {
                            var path = Path.Combine(model.SavePath, file.FileName);
                            if (System.IO.File.Exists(path))
                            {
                                return(Json(new ResultBase <AttachmentsModel>()
                                {
                                    success = false, message = "File đã tồn tại."
                                }));
                            }
                            else
                            {
                                using (var stream = new FileStream(path, FileMode.Create))
                                {
                                    file.CopyTo(stream);
                                }
                                AttachmentsModel attachmentModel = new AttachmentsModel()
                                {
                                    FileName    = file.FileName,
                                    ContentType = file.ContentType,
                                    CreatedDate = DateTime.Now,
                                    FilePath    = path
                                };

                                return(Json(new ResultBase <AttachmentsModel>()
                                {
                                    success = true, data = attachmentModel
                                }));
                            }
                        }
                    }
                }

                return(Json(new ResultBase <AttachmentsModel>()
                {
                    success = true, data = null
                }));
            }
            catch (System.Exception ex)
            {
                return(Json("Upload Failed: " + ex.Message));
            }
        }