Beispiel #1
0
 public void DTO2DB(DTO.FactoryGoodsProcedureDTO dtoItem, ref FactoryGoodsProcedure dbItem, string TmpFile, int userId)
 {
     AutoMapper.Mapper.Map <DTO.FactoryGoodsProcedureDTO, FactoryGoodsProcedure>(dtoItem, dbItem);
 }
Beispiel #2
0
        public void DTO2DB_FactoryGoodsProcedure(DTO.FactoryGoodsProcedureDTO dtoItem, ref FactoryGoodsProcedure dbItem)
        {
            if (dtoItem.FactoryGoodsProcedureDetailDTOs != null) // allow user delete item in case receipt is export
            {
                foreach (var item in dbItem.FactoryGoodsProcedureDetail.ToArray())
                {
                    if (!dtoItem.FactoryGoodsProcedureDetailDTOs.Select(s => s.FactoryGoodsProcedureDetailID).Contains(item.FactoryGoodsProcedureDetailID))
                    {
                        dbItem.FactoryGoodsProcedureDetail.Remove(item);
                    }
                }

                foreach (var item in dtoItem.FactoryGoodsProcedureDetailDTOs)
                {
                    if (item.FactoryStepID == null)
                    {
                        continue;
                    }

                    FactoryGoodsProcedureDetail dbDetail;

                    if (item.FactoryGoodsProcedureDetailID < 0)
                    {
                        dbDetail = new FactoryGoodsProcedureDetail();
                        dbItem.FactoryGoodsProcedureDetail.Add(dbDetail);
                    }
                    else
                    {
                        dbDetail = dbItem.FactoryGoodsProcedureDetail.Where(o => o.FactoryGoodsProcedureDetailID == item.FactoryGoodsProcedureDetailID).FirstOrDefault();
                    }

                    if (dbDetail != null)
                    {
                        AutoMapper.Mapper.Map <DTO.FactoryGoodsProcedureDetailDTO, FactoryGoodsProcedureDetail>(item, dbDetail);
                    }
                }
            }

            AutoMapper.Mapper.Map <DTO.FactoryGoodsProcedureDTO, FactoryGoodsProcedure>(dtoItem, dbItem);
        }
Beispiel #3
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.FactoryGoodsProcedureDTO dtoFactoryGoodsProcedure = ((Newtonsoft.Json.Linq.JObject)dtoItem).ToObject <DTO.FactoryGoodsProcedureDTO>();

            try
            {
                // Check FactoryStep selected or not selected.
                if (dtoFactoryGoodsProcedure.FactoryGoodsProcedureID.CompareTo(0) != 0)
                {
                    bool isValid = InvalidFactoryGoodsProcedureDetail(dtoFactoryGoodsProcedure.FactoryGoodsProcedureDetailDTOs);
                    if (!isValid)
                    {
                        throw new Exception("You have select step.");
                    }
                }

                using (FactoryGoodsProcedureEntities context = CreateContext())
                {
                    FactoryGoodsProcedure dbItem = null;

                    if (id == 0)
                    {
                        dbItem = new FactoryGoodsProcedure();
                        context.FactoryGoodsProcedure.Add(dbItem);

                        // Generate FactoryGoodsProcedureUD continue.
                        List <string> factoryGoodsProcedureUDs    = context.FactoryGoodsProcedure.Select(o => o.FactoryGoodsProcedureUD).ToList();
                        int           nextFactoryGoodsProcedureUD = GenerateFactoryGoodsProcedureUD(factoryGoodsProcedureUDs);

                        string getNext = nextFactoryGoodsProcedureUD.ToString();
                        if (getNext.Length == 1)
                        {
                            getNext = getNext.PadLeft(2, '0');
                        }

                        dtoFactoryGoodsProcedure.FactoryGoodsProcedureUD = getNext;
                    }
                    else
                    {
                        dbItem = context.FactoryGoodsProcedure.Where(o => o.FactoryGoodsProcedureID == id).FirstOrDefault();
                    }

                    if (dbItem == null)
                    {
                        notification.Message = "Data not found !";
                        return(false);
                    }

                    string tmpFile = string.Format("{0}{1}", FrameworkSetting.Setting.AbsoluteUserTempFolder, @"\");

                    converter.DTO2DB_FactoryGoodsProcedure(dtoFactoryGoodsProcedure, ref dbItem);

                    context.FactoryGoodsProcedureDetail.Local.Where(o => o.FactoryGoodsProcedure == null).ToList().ForEach(o => context.FactoryGoodsProcedureDetail.Remove(o));

                    context.SaveChanges();

                    dtoItem = GetData(dbItem.FactoryGoodsProcedureID, out notification).Data;
                    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);
            }
        }