Exemple #1
0
        public override bool UpdateData(int userId, int id, ref object dtoItem, out Notification notification)
        {
            DTO.UnitMngDto unitMngDto = ((JObject)dtoItem).ToObject <DTO.UnitMngDto>();

            notification = new Notification {
                Type = NotificationType.Success
            };

            try
            {
                using (var context = CreatContext())
                {
                    Unit unit = new Unit();

                    if (id == 0)
                    {
                        context.Unit.Add(unit);
                    }

                    if (id > 0)
                    {
                        unit = context.Unit.FirstOrDefault(o => o.UnitID == id);

                        if (unit == null)
                        {
                            notification = new Notification {
                                Type = NotificationType.Error, Message = "Can't Find Data"
                            };
                            return(false);
                        }
                    }

                    this.converter.DTO2DB_UnitMng(unitMngDto, ref unit);
                    context.SaveChanges();

                    dtoItem = this.GetData(unit.UnitID, out notification);
                }
                return(true);
            }
            catch (Exception ex)
            {
                notification = new Notification {
                    Type = NotificationType.Error, Message = ex.Message
                };
                return(false);
            }
        }
Exemple #2
0
 public void DTO2DB_UnitMng(DTO.UnitMngDto dto, ref Unit db)
 {
     AutoMapper.Mapper.Map <DTO.UnitMngDto, Unit>(dto, db);
 }