Example #1
0
        public DTO.ProductionFrameWeightData UpdateData(int userID, int id, Hashtable filters, out Notification notification)
        {
            DTO.ProductionFrameWeightData dtoItem = ((Newtonsoft.Json.Linq.JObject)filters["view"]).ToObject <DTO.ProductionFrameWeightData>();

            notification      = new Notification();
            notification.Type = NotificationType.Success;

            try
            {
                using (var context = CreateContext())
                {
                    ProductionFrameWeight dbItem;

                    if (id <= 0)
                    {
                        dbItem = new ProductionFrameWeight();
                        context.ProductionFrameWeight.Add(dbItem);
                    }
                    else
                    {
                        dbItem = context.ProductionFrameWeight.FirstOrDefault(o => o.ProductionFrameWeightID == id);
                    }

                    if (dbItem == null)
                    {
                        notification.Type    = NotificationType.Error;
                        notification.Message = "Can't found data of ProductionFrameWeight!";
                    }
                    else
                    {
                        converter.DTO2DB_ProductionFrameWeight(userID, dtoItem, ref dbItem);

                        context.SaveChanges();

                        dtoItem = GetData(userID, dbItem.ProductionFrameWeightID, out notification);
                    }
                }
            }
            catch (Exception ex)
            {
                notification.Type    = NotificationType.Error;
                notification.Message = Library.Helper.GetInnerException(ex).Message;
            }

            return(dtoItem);
        }
Example #2
0
        public bool DeleteData(int userID, int id, out Notification notification)
        {
            notification      = new Notification();
            notification.Type = NotificationType.Success;

            try
            {
                using (var context = CreateContext())
                {
                    ProductionFrameWeight dbItem = context.ProductionFrameWeight.FirstOrDefault(o => o.ProductionFrameWeightID == id);

                    if (dbItem == null)
                    {
                        notification.Type    = NotificationType.Error;
                        notification.Message = "Can't found data of ProductionFrameWeight!";

                        return(false);
                    }
                    else
                    {
                        context.ProductionFrameWeight.Remove(dbItem);

                        context.SaveChanges();

                        return(true);
                    }
                }
            }
            catch (Exception ex)
            {
                notification.Type    = NotificationType.Error;
                notification.Message = Library.Helper.GetInnerException(ex).Message;

                return(false);
            }
        }
Example #3
0
        public void DTO2DB_ProductionFrameWeight(int userID, DTO.ProductionFrameWeightData dtoItem, ref ProductionFrameWeight dbItem)
        {
            AutoMapper.Mapper.Map <DTO.ProductionFrameWeightData, ProductionFrameWeight>(dtoItem, dbItem);

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

            if (dtoItem.ProductionFrameWeightHistory != null)
            {
                foreach (var dtoItemDetail in dbItem.ProductionFrameWeightHistory.ToList())
                {
                    if (!dtoItem.ProductionFrameWeightHistory.Select(s => s.ProductionFrameWeightHistoryID).Contains(dtoItemDetail.ProductionFrameWeightHistoryID))
                    {
                        dbItem.ProductionFrameWeightHistory.Remove(dtoItemDetail);
                    }
                }

                foreach (var dtoItemDetail in dtoItem.ProductionFrameWeightHistory.ToList())
                {
                    ProductionFrameWeightHistory dbItemDetail;

                    if (dtoItemDetail.ProductionFrameWeightHistoryID <= 0)
                    {
                        dbItemDetail = new ProductionFrameWeightHistory();
                        dbItem.ProductionFrameWeightHistory.Add(dbItemDetail);

                        if (dbItemDetail != null)
                        {
                            AutoMapper.Mapper.Map <DTO.ProductionFrameWeightHistoryData, ProductionFrameWeightHistory>(dtoItemDetail, dbItemDetail);
                            dbItemDetail.UpdatedBy   = userID;
                            dbItemDetail.UpdatedDate = DateTime.Now;
                            dbItemDetail.Remark      = dtoItem.Remark;
                        }
                    }
                    else
                    {
                        dbItemDetail = dbItem.ProductionFrameWeightHistory.FirstOrDefault(o => o.ProductionFrameWeightHistoryID == dtoItemDetail.ProductionFrameWeightHistoryID);
                    }
                }
            }
        }