Example #1
0
        public object UpdateData(int userID, System.Collections.Hashtable filters, out Library.DTO.Notification notification)
        {
            notification      = new Library.DTO.Notification();
            notification.Type = Library.DTO.NotificationType.Success;

            try
            {
                string paramSeason    = filters.ContainsKey("season") && filters["season"] != null && !string.IsNullOrEmpty(filters["season"].ToString().Trim()) ? filters["season"].ToString() : null;
                int?   paramFactoryID = filters.ContainsKey("factoryID") && filters["factoryID"] != null && !string.IsNullOrEmpty(filters["factoryID"].ToString().Trim()) ? (int?)Convert.ToInt32(filters["factoryID"].ToString()) : null;

                List <DTO.FactoryPlanningData> dataView = filters.ContainsKey("dataView") && filters["dataView"] != null && !string.IsNullOrEmpty(filters["dataView"].ToString().Trim()) ? ((Newtonsoft.Json.Linq.JArray)filters["dataView"]).ToObject <List <DTO.FactoryPlanningData> >() : null;

                using (var context = CreateContext())
                {
                    foreach (var dtoItem in dataView)
                    {
                        FactoryPlanning dbItem;

                        if (dtoItem.FactoryPlanningID == 0)
                        {
                            dbItem = new FactoryPlanning();
                            context.FactoryPlanning.Add(dbItem);
                        }
                        else
                        {
                            dbItem = context.FactoryPlanning.FirstOrDefault(o => o.FactoryPlanningID == dtoItem.FactoryPlanningID);
                        }

                        if (dbItem == null)
                        {
                            continue;
                        }

                        converter.DTO2DB_FactoryPlanning(dtoItem, ref dbItem);

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

                    context.SaveChanges();
                }

                return(GetDataWithFilter(userID, filters, 20, 1, "PrimaryID", "ASC", out int totalRows, out notification));
            }
            catch (Exception ex)
            {
                notification.Type    = Library.DTO.NotificationType.Error;
                notification.Message = Library.Helper.GetInnerException(ex).Message;

                return(null);
            }
        }
Example #2
0
 public void DTO2DB_FactoryPlanning(DTO.FactoryPlanningData dtoItem, ref FactoryPlanning dbItem)
 {
     AutoMapper.Mapper.Map <DTO.FactoryPlanningData, FactoryPlanning>(dtoItem, dbItem);
 }