Ejemplo n.º 1
0
 public void DTO2BD(DTO.ProductionItemTypeDTO dtoItem, ref ProductionItemType dbItem)
 {
     AutoMapper.Mapper.Map <DTO.ProductionItemTypeDTO, ProductionItemType>(dtoItem, dbItem);
     dbItem.UpdatedDate = dtoItem.UpdatedDate.ConvertStringToDateTime();
 }
Ejemplo n.º 2
0
        public override bool UpdateData(int userId, int id, ref object dtoItem, out Library.DTO.Notification notification)
        {
            DTO.ProductionItemTypeDTO dtoProductionItemType = ((Newtonsoft.Json.Linq.JObject)dtoItem).ToObject <DTO.ProductionItemTypeDTO>();
            notification = new Library.DTO.Notification()
            {
                Type = Library.DTO.NotificationType.Success
            };
            int    number;
            string indexName;

            try
            {
                using (ProductionItemTypeEntities context = CreateContext())
                {
                    ProductionItemType dbItem = null;
                    if (id == 0)
                    {
                        dbItem = new ProductionItemType();
                        context.ProductionItemType.Add(dbItem);
                    }
                    else
                    {
                        dbItem = context.ProductionItemType.FirstOrDefault(o => o.ProductionItemTypeID == id);
                    }

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

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

                        context.SaveChanges();

                        dtoItem = GetData(userId, dbItem.ProductionItemTypeID, 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_ProductionItemTypeUDUnique":
                        notification.Message = "Code must be unique! Please select other code!";
                        break;
                    }
                }
                else
                {
                    notification.Message = dEx.Message;
                }
                return(false);
            }
        }