Ejemplo n.º 1
0
 public void DTO2DB_OfferSeason(int userId, DTO.OfferSeasonDTO dtoItem, ref OfferSeason dbItem)
 {
     AutoMapper.Mapper.Map <DTO.OfferSeasonDTO, OfferSeason>(dtoItem, dbItem);
     if (dtoItem.OfferSeasonID <= 0)
     {
         dbItem.CreatedBy   = userId;
         dbItem.CreatedDate = DateTime.Now;
     }
 }
Ejemplo n.º 2
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.OfferSeasonDTO dtoOfferSeason = ((Newtonsoft.Json.Linq.JObject)dtoItem).ToObject <DTO.OfferSeasonDTO>();
            try
            {
                using (OfferSeasonMngEntities context = CreateContext())
                {
                    OfferSeason dbItem = null;
                    if (id == 0)
                    {
                        dbItem = new OfferSeason();
                        context.OfferSeason.Add(dbItem);
                    }
                    else
                    {
                        dbItem = context.OfferSeason.Where(o => o.OfferSeasonID == id).FirstOrDefault();
                    }
                    if (dbItem == null)
                    {
                        notification.Message = "data not found!";
                        return(false);
                    }
                    else
                    {
                        if (!dtoOfferSeason.OfferSeasonTypeID.HasValue)
                        {
                            throw new Exception("Please select type of offer");
                        }
                        if (dtoOfferSeason.OfferSeasonID == 0)
                        {
                            dtoOfferSeason.OfferSeasonUD = context.OfferSeasonMng_function_GenerateOfferSeasonCode(dtoOfferSeason.OfferSeasonID, dtoOfferSeason.Season, dtoOfferSeason.ClientID).FirstOrDefault();
                        }

                        //convert to db
                        converter.DTO2DB_OfferSeason(userId, dtoOfferSeason, ref dbItem);

                        //save data
                        context.SaveChanges();

                        //get return data
                        dtoItem = GetData(userId, dbItem.OfferSeasonID, null, out notification).OfferSeasonDTO;
                        return(true);
                    }
                }
            }
            catch (Exception ex)
            {
                notification.Type    = Library.DTO.NotificationType.Error;
                notification.Message = Library.Helper.HandleExceptionSingleLine(ex);
                return(false);
            }
        }
Ejemplo n.º 3
0
        public DTO.OfferSeasonDetailDTO UpdateOfferSeasonDetail(int userId, int offerSeasonID, int offerSeasonDetailID, object dtoItem, out Library.DTO.Notification notification)
        {
            notification = new Library.DTO.Notification()
            {
                Type = Library.DTO.NotificationType.Success
            };
            DTO.OfferSeasonDetailDTO dtoOfferSeasonDetail = ((Newtonsoft.Json.Linq.JObject)dtoItem).ToObject <DTO.OfferSeasonDetailDTO>();
            try
            {
                using (OfferSeasonMngEntities context = CreateContext())
                {
                    //find offer season to attach offerSeasonDetail
                    OfferSeason dbOfferSeason = context.OfferSeason.Where(o => o.OfferSeasonID == offerSeasonID).FirstOrDefault();
                    if (dbOfferSeason == null)
                    {
                        throw new Exception("Could not find offer season");
                    }

                    //offer seasons detail
                    OfferSeasonDetail dbItem   = null;
                    bool isAllowEditProperties = true;
                    if (offerSeasonDetailID > 0)
                    {
                        //get item to update
                        dbItem = context.OfferSeasonDetail.Where(o => o.OfferSeasonDetailID == offerSeasonDetailID).FirstOrDefault();

                        //check item is in factory order so we can allow edit property of item
                        bool isInFactoryOrder = context.OfferSeasonMng_function_CheckOfferItemIsInFactoryOrder(offerSeasonDetailID).FirstOrDefault().Value > 0;
                        isAllowEditProperties = !isInFactoryOrder;

                        //get admin permission
                        Module.Framework.DAL.DataFactory fwFactory = new Module.Framework.DAL.DataFactory();
                        if (fwFactory.HasSpecialPermission(userId, Module.Framework.ConstantIdentifier.SPECIAL_PERMISSION_CHANGE_OFFER_ITEM_OPTION))
                        {
                            isAllowEditProperties = true;
                        }
                    }
                    else
                    {
                        //create new OfferSeasonDetail
                        dbItem = new OfferSeasonDetail();
                        dbOfferSeason.OfferSeasonDetail.Add(dbItem);
                    }
                    if (dbItem == null)
                    {
                        throw new Exception("data not found offer season item!");
                    }
                    else
                    {
                        //convert dto 2 db
                        converter.DTO2DB_OfferSeasonDetail(userId, dbOfferSeason.OfferSeasonTypeID, offerSeasonDetailID, dtoOfferSeasonDetail, isAllowEditProperties, ref dbItem);
                        if (dbItem.IsPlaningPurchasingPriceSelected.HasValue && dbItem.IsPlaningPurchasingPriceSelected.Value && dbItem.PlaningPurchasingPriceSelectedBy == null)
                        {
                            dbItem.PlaningPurchasingPriceSelectedBy   = userId;
                            dbItem.PlaningPurchasingPriceSelectedDate = DateTime.Now;
                        }

                        //save data
                        context.SaveChanges();

                        //auto make quotation request to quotation
                        //context.OfferSeasonQuotatonRequestMng_function_AddOfferSeasonItemToQuotation(dbItem.OfferSeasonDetailID, userId);
                        // disabled, using trigger instead

                        //auto reset quotation status if change property of item
                        if (dtoOfferSeasonDetail.IsChangedProperties.HasValue && dtoOfferSeasonDetail.IsChangedProperties.Value && isAllowEditProperties)
                        {
                            context.OfferSeasonMng_function_ResetStatusOfQuotation(dbItem.OfferSeasonDetailID);
                        }

                        //get return data
                        dtoOfferSeasonDetail = GetOfferSeasonDetail(dbItem.OfferSeasonDetailID, out notification);

                        return(dtoOfferSeasonDetail);
                    }
                }
            }
            catch (Exception ex)
            {
                notification.Type    = Library.DTO.NotificationType.Error;
                notification.Message = Library.Helper.HandleExceptionSingleLine(ex);
                return(null);
            }
        }