コード例 #1
0
        public override bool UpdateData(int userId, int id, ref object dtoItem, out Library.DTO.Notification notification)
        {
            notification = new Library.DTO.Notification()
            {
                Type = Library.DTO.NotificationType.Success
            };
            DTO.FactoryTeamDTO dtoFactoryTeam = ((Newtonsoft.Json.Linq.JObject)dtoItem).ToObject <DTO.FactoryTeamDTO>();
            try
            {
                using (FactoryTeamEntities context = CreateContext())
                {
                    FactoryTeam dbItem = null;
                    if (id > 0)
                    {
                        dbItem = context.FactoryTeam.Where(o => o.FactoryTeamID == id).FirstOrDefault();
                    }
                    else
                    {
                        dbItem = new FactoryTeam();
                        context.FactoryTeam.Add(dbItem);
                    }

                    if (dbItem == null)
                    {
                        notification.Message = "data not found!";
                        return(false);
                    }
                    else
                    {
                        //convert dto to db
                        converter.DTO2DB_FactoryTeam(dtoFactoryTeam, ref dbItem);
                        context.SaveChanges();
                        //get return data
                        dtoItem = GetData(dbItem.FactoryTeamID, out notification);
                        return(true);
                    }
                }
            }
            catch (Exception ex)
            {
                notification.Type    = Library.DTO.NotificationType.Error;
                notification.Message = ex.Message;
                notification.DetailMessage.Add(ex.Message);
                if (ex.GetBaseException() != null)
                {
                    notification.DetailMessage.Add(ex.GetBaseException().Message);
                }
                return(false);
            }
        }
コード例 #2
0
 public void DTO2DB_FactoryTeam(DTO.FactoryTeamDTO dtoItem, ref FactoryTeam dbItem)
 {
     AutoMapper.Mapper.Map <DTO.FactoryTeamDTO, FactoryTeam>(dtoItem, dbItem);
 }
コード例 #3
0
 public DTO.FactoryTeamDTO DB2DTO_FactoryTeam(FactoryTeam dbItem)
 {
     return(AutoMapper.Mapper.Map <FactoryTeam, DTO.FactoryTeamDTO>(dbItem));
 }