Ejemplo n.º 1
0
        public override bool UpdateData(int userId, int id, ref object dtoItem, out Library.DTO.Notification notification)
        {
            DTO.ProductionItemSpecDTO dtoProductionItemSpec = ((Newtonsoft.Json.Linq.JObject)dtoItem).ToObject <DTO.ProductionItemSpecDTO>();
            notification = new Library.DTO.Notification()
            {
                Type = Library.DTO.NotificationType.Success
            };
            int    number;
            string indexName;

            try
            {
                using (ProductionItemSpecEntities context = CreateContext())
                {
                    ProductionItemSpec dbItem = null;
                    if (id == 0)
                    {
                        dbItem = new ProductionItemSpec();
                        context.ProductionItemSpec.Add(dbItem);
                    }
                    else
                    {
                        dbItem = context.ProductionItemSpec.FirstOrDefault(o => o.ProductionItemSpecID == id);
                    }

                    if (dbItem == null)
                    {
                        notification.Message = "Production Item Spec not found!";
                        return(false);
                    }
                    else
                    {
                        //convert dto to db
                        converter.DTO2BD(dtoProductionItemSpec, ref dbItem);

                        dbItem.UpdatedDate = DateTime.Now;
                        dbItem.UpdatedBy   = userId;

                        context.SaveChanges();

                        dtoItem = GetData(userId, dbItem.ProductionItemSpecID, out notification).Data;

                        return(true);
                    }
                }
            }

            catch (System.Data.DataException dEx)
            {
                notification.Type = Library.DTO.NotificationType.Error;
                Library.ErrorHelper.DataExceptionParser(dEx, out number, out indexName);
                if (number == 2601 && !string.IsNullOrEmpty(indexName))
                {
                    switch (indexName)
                    {
                    case "IX_ProductionItemSpecUnique":
                        notification.Message = "Code must be unique! Please select other code!";
                        break;
                    }
                }
                else
                {
                    notification.Message = dEx.Message;
                }
                return(false);
            }
        }
Ejemplo n.º 2
0
 public void DTO2BD(DTO.ProductionItemSpecDTO dtoItem, ref ProductionItemSpec dbItem)
 {
     AutoMapper.Mapper.Map <DTO.ProductionItemSpecDTO, ProductionItemSpec>(dtoItem, dbItem);
     dbItem.UpdatedDate = dtoItem.UpdatedDate.ConvertStringToDateTime();
 }