Exemplo n.º 1
0
 public bool DeleteMaterialGroupTeam(int id, out Library.DTO.Notification notification)
 {
     notification = new Library.DTO.Notification {
         Type = Library.DTO.NotificationType.Success
     };
     try
     {
         using (FactoryTeamEntities context = CreateContext())
         {
             var dbItem = context.FactoryMaterialGroupTeam.Where(o => o.FactoryMaterialGroupTeamID == id).FirstOrDefault();
             context.FactoryMaterialGroupTeam.Remove(dbItem);
             context.SaveChanges();
         }
         return(true);
     }
     catch (Exception ex)
     {
         notification.Type    = Library.DTO.NotificationType.Error;
         notification.Message = ex.Message;
         notification.DetailMessage.Add(ex.Message);
         if (ex.GetBaseException() != null)
         {
             notification.DetailMessage.Add(ex.GetBaseException().Message);
         }
         return(false);
     }
 }
Exemplo n.º 2
0
 public int CreateFactoryTeamStep(int factoryTeamID, object dtoObjectItem, out Library.DTO.Notification notification)
 {
     notification = new Library.DTO.Notification()
     {
         Type = Library.DTO.NotificationType.Success, Message = "Update success"
     };
     DTO.FactoryTeamStepDTO dtoItem = ((Newtonsoft.Json.Linq.JObject)dtoObjectItem).ToObject <DTO.FactoryTeamStepDTO>();
     try
     {
         if (!dtoItem.FactoryStepID.HasValue)
         {
             throw new Exception("You have to select step");
         }
         if (!dtoItem.StepIndex.HasValue)
         {
             throw new Exception("You have to fill-in index");
         }
         using (FactoryTeamEntities context = CreateContext())
         {
             FactoryTeamStep dbItem;
             if (dtoItem.FactoryTeamStepID > 0)
             {
                 dbItem = context.FactoryTeamStep.Where(o => o.FactoryTeamStepID == dtoItem.FactoryTeamStepID).FirstOrDefault();
             }
             else
             {
                 dbItem = new FactoryTeamStep();
                 dbItem.FactoryTeamID = factoryTeamID;
                 context.FactoryTeamStep.Add(dbItem);
             }
             if (dbItem != null)
             {
                 dbItem.FactoryStepID = dtoItem.FactoryStepID;
                 dbItem.StepIndex     = dtoItem.StepIndex;
             }
             else
             {
                 throw new Exception("Could not find data. You have to save data before update team step");
             }
             context.SaveChanges();
             return(dbItem.FactoryTeamStepID);
         }
     }
     catch (Exception ex)
     {
         notification.Type    = Library.DTO.NotificationType.Error;
         notification.Message = ex.Message;
         notification.DetailMessage.Add(ex.Message);
         if (ex.GetBaseException() != null)
         {
             notification.DetailMessage.Add(ex.GetBaseException().Message);
         }
         return(-1);
     }
 }
Exemplo n.º 3
0
        public override DTO.SearchFormDataDTO GetDataWithFilter(Hashtable filters, int pageSize, int pageIndex, string orderBy, string orderDirection, out int totalRows, out Library.DTO.Notification notification)
        {
            DTO.SearchFormDataDTO data = new DTO.SearchFormDataDTO();
            notification = new Library.DTO.Notification()
            {
                Type = Library.DTO.NotificationType.Success
            };
            totalRows = 0;
            Module.Support.DAL.DataFactory supportFactory = new Support.DAL.DataFactory();

            string FactoryTeamUD = string.Empty;
            string FactoryTeamNM = string.Empty;
            int?   factoryStepID = null;

            if (filters.ContainsKey("factoryTeamUD"))
            {
                FactoryTeamUD = filters["factoryTeamUD"].ToString();
            }
            if (filters.ContainsKey("factoryTeamNM"))
            {
                FactoryTeamNM = filters["factoryTeamNM"].ToString();
            }
            if (filters.ContainsKey("factoryStepID") && filters["factoryStepID"] != null)
            {
                factoryStepID = Convert.ToInt32(filters["factoryStepID"].ToString());
            }

            try
            {
                using (FactoryTeamEntities context = CreateContext())
                {
                    totalRows = context.FactoryTeamMng_function_SearchFactoryTeam(orderBy, orderDirection, FactoryTeamUD, FactoryTeamNM, factoryStepID).Count();
                    var result = context.FactoryTeamMng_function_SearchFactoryTeam(orderBy, orderDirection, FactoryTeamUD, FactoryTeamNM, factoryStepID);
                    data.Data = converter.DB2DTO_FactoryTeamSearch(result.Skip(pageSize * (pageIndex - 1)).Take(pageSize).ToList());
                }
                data.FactorySteps = supportFactory.GetFactoryStep();
                return(data);
            }
            catch (Exception ex)
            {
                notification.Type    = Library.DTO.NotificationType.Error;
                notification.Message = ex.Message;
                notification.DetailMessage.Add(ex.Message);
                if (ex.GetBaseException() != null)
                {
                    notification.DetailMessage.Add(ex.GetBaseException().Message);
                }
                return(new DTO.SearchFormDataDTO());
            }
        }
Exemplo n.º 4
0
        public override bool UpdateData(int userId, int id, ref object dtoItem, out Library.DTO.Notification notification)
        {
            notification = new Library.DTO.Notification()
            {
                Type = Library.DTO.NotificationType.Success
            };
            DTO.FactoryTeamDTO dtoFactoryTeam = ((Newtonsoft.Json.Linq.JObject)dtoItem).ToObject <DTO.FactoryTeamDTO>();
            try
            {
                using (FactoryTeamEntities context = CreateContext())
                {
                    FactoryTeam dbItem = null;
                    if (id > 0)
                    {
                        dbItem = context.FactoryTeam.Where(o => o.FactoryTeamID == id).FirstOrDefault();
                    }
                    else
                    {
                        dbItem = new FactoryTeam();
                        context.FactoryTeam.Add(dbItem);
                    }

                    if (dbItem == null)
                    {
                        notification.Message = "data not found!";
                        return(false);
                    }
                    else
                    {
                        //convert dto to db
                        converter.DTO2DB_FactoryTeam(dtoFactoryTeam, ref dbItem);
                        context.SaveChanges();
                        //get return data
                        dtoItem = GetData(dbItem.FactoryTeamID, out notification);
                        return(true);
                    }
                }
            }
            catch (Exception ex)
            {
                notification.Type    = Library.DTO.NotificationType.Error;
                notification.Message = ex.Message;
                notification.DetailMessage.Add(ex.Message);
                if (ex.GetBaseException() != null)
                {
                    notification.DetailMessage.Add(ex.GetBaseException().Message);
                }
                return(false);
            }
        }
Exemplo n.º 5
0
 public override DTO.EditFormDataDTO GetData(int id, out Library.DTO.Notification notification)
 {
     notification = new Library.DTO.Notification()
     {
         Type = Library.DTO.NotificationType.Success
     };
     Module.Support.DAL.DataFactory supportFactory = new Support.DAL.DataFactory();
     DTO.EditFormDataDTO            dtoItem        = new DTO.EditFormDataDTO();
     try
     {
         using (FactoryTeamEntities context = CreateContext())
         {
             if (id > 0)
             {
                 FactoryTeam dbItem;
                 dbItem       = context.FactoryTeam.FirstOrDefault(o => o.FactoryTeamID == id);
                 dtoItem.Data = converter.DB2DTO_FactoryTeam(dbItem);
             }
             else
             {
                 dtoItem.Data = new DTO.FactoryTeamDTO();
                 dtoItem.Data.FactoryMaterialGroupTeamDTOs = new List <DTO.FactoryMaterialGroupTeamDTO>();
                 dtoItem.Data.FactoryTeamStepDTOs          = new List <DTO.FactoryTeamStepDTO>();
             }
             dtoItem.FactorySteps          = supportFactory.GetFactoryStep();
             dtoItem.FactoryMaterialGroups = supportFactory.GetFactoryMaterialGroup();
             return(dtoItem);
         }
     }
     catch (Exception ex)
     {
         notification.Type    = Library.DTO.NotificationType.Error;
         notification.Message = ex.Message;
         notification.DetailMessage.Add(ex.Message);
         if (ex.GetBaseException() != null)
         {
             notification.DetailMessage.Add(ex.GetBaseException().Message);
         }
         return(null);
     }
 }