Ejemplo n.º 1
0
        public override bool UpdateData(int userId, int id, ref object dtoItem, out Library.DTO.Notification notification)
        {
            DTO.Material dtoMaterial = ((Newtonsoft.Json.Linq.JObject)dtoItem).ToObject <DTO.Material>();
            notification = new Library.DTO.Notification()
            {
                Type = Library.DTO.NotificationType.Success
            };
            try
            {
                using (MaterialMngEntities context = CreateContext())
                {
                    Material dbItem = null;
                    if (id == 0)
                    {
                        dbItem = new Material();
                        context.Material.Add(dbItem);
                    }
                    else
                    {
                        dbItem = context.Material.FirstOrDefault(o => o.MaterialID == id);
                    }

                    if (dbItem == null)
                    {
                        notification.Message = "Material not found!";
                        return(false);
                    }
                    else
                    {
                        converter.DTO2DB(dtoMaterial, ref dbItem, FrameworkSetting.Setting.AbsoluteUserTempFolder + userId.ToString() + @"\", userId);
                        context.SaveChanges();
                        dtoItem = GetData(dbItem.MaterialID, out notification).Data;
                        return(true);
                    }
                }
            }
            catch (Exception ex)
            {
                notification = new Library.DTO.Notification()
                {
                    Message = ex.Message, Type = Library.DTO.NotificationType.Error
                };
                return(false);
            }
        }
Ejemplo n.º 2
0
 public void DTO2DB(DTO.Material dtoItem, ref Material dbItem, string TmpFile, int userId)
 {
     AutoMapper.Mapper.Map <DTO.Material, Material>(dtoItem, dbItem);
 }