Exemple #1
0
        public override bool UpdateData(int userId, int id, ref object dtoItem, out Notification notification)
        {
            notification = new Notification()
            {
                Type = NotificationType.Success
            };
            DTO.TestStandardDTO dtoItems = ((Newtonsoft.Json.Linq.JObject)dtoItem).ToObject <DTO.TestStandardDTO>();
            try
            {
                using (var context = CreatContex())
                {
                    TestStandard dbItem;
                    if (id == 0)
                    {
                        dbItem = new TestStandard();
                        context.TestStandard.Add(dbItem);
                    }
                    else
                    {
                        dbItem = context.TestStandard.Where(o => o.TestStandardID == id).FirstOrDefault();
                    }
                    if (dbItem == null)
                    {
                        notification.Message = "Data Not found !";
                        return(false);
                    }
                    else
                    {
                        converter.DTO2DB_TestStandard(dtoItems, ref dbItem);
                        context.SaveChanges();

                        dtoItem = GetData(dbItem.TestStandardID, out notification).Data;
                        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);
            }
        }
Exemple #2
0
 public void DTO2DB_TestStandard(DTO.TestStandardDTO dtoItem, ref TestStandard dbItem)
 {
     AutoMapper.Mapper.Map <DTO.TestStandardDTO, TestStandard>(dtoItem, dbItem);
 }