Пример #1
0
        public void DTO2DB(List <DTO.OfferSeasonQuotationRequestDetailDTO> dtoItems, ref OfferSeasonQuotationRequest dbItem, int userId)
        {
            throw new NotImplementedException();
            //string TmpFile = FrameworkSetting.Setting.AbsoluteUserTempFolder + userId.ToString() + @"\";

            //foreach (OfferSeasonQuotationRequestDetail dbDetail in dbItem.OfferSeasonQuotationRequestDetail.ToArray())
            //{
            //    if (!dtoItems.Select(o => o.OfferSeasonQuotationRequestDetailID).Contains(dbDetail.OfferSeasonQuotationRequestDetailID))
            //    {
            //        dbItem.OfferSeasonQuotationRequestDetail.Remove(dbDetail);
            //    }
            //}
            //foreach (DTO.OfferSeasonQuotationRequestDetailDTO dtoDetail in dtoItems)
            //{
            //    OfferSeasonQuotationRequestDetail dbDetail;
            //    if (dtoDetail.OfferSeasonQuotationRequestDetailID <= 0)
            //    {
            //        dbDetail = new OfferSeasonQuotationRequestDetail();
            //        dbItem.OfferSeasonQuotationRequestDetail.Add(dbDetail);
            //    }
            //    else
            //    {
            //        dbDetail = dbItem.OfferSeasonQuotationRequestDetail.FirstOrDefault(o => o.OfferSeasonQuotationRequestDetailID == dtoDetail.OfferSeasonQuotationRequestDetailID);
            //    }

            //    if (dbDetail != null)
            //    {
            //        dbDetail.UpdatedDate = DateTime.Now;
            //        dbDetail.UpdatedBy = userId;
            //        AutoMapper.Mapper.Map<DTO.OfferSeasonQuotationRequestDetailDTO, OfferSeasonQuotationRequestDetail>(dtoDetail, dbDetail);
            //    }
            //}
        }
Пример #2
0
        public override bool UpdateData(int userId, int id, ref object dtoItem, out Library.DTO.Notification notification)
        {
            List <int> dtoFactories = ((Newtonsoft.Json.Linq.JArray)dtoItem).ToObject <List <int> >();

            notification = new Library.DTO.Notification()
            {
                Type = Library.DTO.NotificationType.Success
            };
            try
            {
                using (OfferSeasonQuotationRequestMngEntities context = CreateContext())
                {
                    OfferSeasonQuotationRequest dbItem = null;
                    if (id == 0)
                    {
                        throw new Exception("Invalid request!");
                    }
                    else
                    {
                        dbItem = context.OfferSeasonQuotationRequest.FirstOrDefault(o => o.OfferSeasonQuotationRequestID == id);
                    }

                    if (dbItem == null)
                    {
                        notification.Message = "Request not found!";
                        return(false);
                    }
                    else
                    {
                        //converter.DTO2DB(dtoDetails, ref dbItem, userId);
                        foreach (int factoryId in dtoFactories)
                        {
                            dbItem.OfferSeasonQuotationRequestDetail.Add(new OfferSeasonQuotationRequestDetail {
                                UpdatedBy = userId, UpdatedDate = DateTime.Now, FactoryID = factoryId
                            });
                        }
                        context.SaveChanges();
                        context.OfferSeasonQuotatonRequestMng_function_InsertIntoQuotationDetail(id);
                        context.SaveChanges();
                        return(true);
                    }
                }
            }
            catch (Exception ex)
            {
                notification.Type    = Library.DTO.NotificationType.Error;
                notification.Message = Library.Helper.HandleExceptionSingleLine(ex);
                return(false);
            }
        }