Exemplo n.º 1
0
        public ActionResult Update(RegisterUpdateDTO dto)
        {
            UserLoginDTO lng = Session["UserLoginInfo"] as UserLoginDTO;

            dto.UserInfo      = lng.UserInfo();
            dto.AttachmentIDs = new List <RegisterAttachmentDTO>();
            HttpContext.Request.Files.AllKeys.Select(key => HttpContext.Request.Files[key]).Where(p => !string.IsNullOrEmpty(p.FileName)).ToList().ForEach(p =>
            {
                var att = new RegisterAttachmentDTO
                {
                    AttachmentID   = Guid.NewGuid(),
                    AttachmentName = p.FileName,
                    AttachmentSize = p.ContentLength,
                };
                p.SaveAs(Const.RealRegisterPath(att.AttachmentID.ToString()));
                dto.AttachmentIDs.Add(att);
            });

            var pt = ProductManagementProvider.GetProductType(dto.ProductTypeID.Value);
            var pr = ProductManagementProvider.GetOneProductLine(dto.ProductLineID.Value);

            dto.ProductLineName = pr.Object.ProductLineName;
            dto.ProductTypeName = pt.Object.ProductTypeName;
            var result = _RegisterService.Update(dto);

            return(new JsonResult(result));
        }
Exemplo n.º 2
0
 public DocumentResultDTO Update(RegisterUpdateDTO model)
 {
     return(_RegisterService.Update(model));
 }
Exemplo n.º 3
0
        /// <summary>
        /// 修改
        /// </summary>
        public DocumentResultDTO Update(RegisterUpdateDTO model)
        {
            try
            {
                var token  = model.UserInfo as UserInfoDTO;
                var entity = document.Document_Register.FirstOrDefault(p => p.RegisterID == model.RegisterID);
                if (!string.IsNullOrWhiteSpace(model.Title))
                {
                    entity.Title = model.Title;
                }
                if (model.ProductTypeID.HasValue && !string.IsNullOrWhiteSpace(model.ProductTypeName))
                {
                    entity.ProductTypeID   = model.ProductTypeID;
                    entity.ProductTypeName = model.ProductTypeName;
                }
                if (model.ProductLineID.HasValue && !string.IsNullOrWhiteSpace(model.ProductLineName))
                {
                    entity.ProductLineID   = model.ProductLineID;
                    entity.ProductLineName = model.ProductLineName;
                }
                if (!string.IsNullOrWhiteSpace(model.ProductNo))
                {
                    entity.ProductNo = model.ProductNo;
                }
                if (model.ValidDate.HasValue)
                {
                    entity.ValidDate = model.ValidDate;
                }
                entity.PublisherID = token.UserID;
                entity.Publisher   = token.FullName;
                entity.UpdateDate  = DateTime.Now;

                if (model.DeleteAttachmentIDs != null)
                {
                    model.DeleteAttachmentIDs.ForEach(p =>
                    {
                        var att = document.Document_RegisterAttachment.Find(p);
                        if (att == null)
                        {
                            return;
                        }
                        document.Document_RegisterAttachmentDownload.RemoveRange(att.Document_RegisterAttachmentDownload);
                        document.Document_RegisterAttachment.Remove(att);
                    });
                }

                document.Document_RegisterAttachment.AddRange(model.AttachmentIDs.Select(p => new Document_RegisterAttachment
                {
                    AttachmentID   = p.AttachmentID,
                    AttachmentName = p.AttachmentName,
                    AttachmentSize = p.AttachmentSize,
                    RegisterID     = model.RegisterID
                }));
                document.SaveChanges();
                //entity.Document_RegisterAttachment.ToList().ForEach(att =>
                //{
                //    document.Document_RegisterAttachment.Remove(att);
                //});
                //if (model.AttachmentIDs != null)
                //{
                //    model.AttachmentIDs.Select(att => document.Document_RegisterAttachment.Find(att.AttachmentID)).ToList().ForEach(att =>
                //    {
                //        entity.Document_RegisterAttachment.Add(att);
                //    });
                //}
                document.SaveChanges();
                return(new DocumentResultDTO {
                    success = true
                });
            }
            catch (Exception ex)
            {
                return(new DocumentResultDTO {
                    success = false, message = ex.Message
                });
            }
        }