Exemple #1
0
        public bool UpdateItemData(int userId, int id, ref object dtoItem, out Library.DTO.Notification notification)
        {
            DTO.ItemData.ProductDTO dtoProduct = ((Newtonsoft.Json.Linq.JObject)dtoItem).ToObject <DTO.ItemData.ProductDTO>();
            notification = new Library.DTO.Notification()
            {
                Type = Library.DTO.NotificationType.Success
            };
            try
            {
                using (Sample3MngEntities context = CreateContext())
                {
                    SampleProduct dbItem = context.SampleProduct.FirstOrDefault(o => o.SampleProductID == id);
                    if (dbItem == null)
                    {
                        notification.Message = "Sample Product not found!";
                        return(false);
                    }
                    else
                    {
                        converter.DTO2DB_ItemData(dtoProduct, ref dbItem);
                        context.SaveChanges();
                    }

                    dtoItem = GetItemData(dbItem.SampleProductID, out notification).Data;
                    return(true);
                }
            }
            catch (Exception ex)
            {
                notification = new Library.DTO.Notification()
                {
                    Message = ex.Message, Type = Library.DTO.NotificationType.Error
                };
                return(false);
            }
        }
 public void DTO2DB_ItemData(DTO.ItemData.ProductDTO dtoItem, ref SampleProduct dbItem)
 {
     AutoMapper.Mapper.Map <DTO.ItemData.ProductDTO, SampleProduct>(dtoItem, dbItem);
 }