Esempio n. 1
0
        public ActionResult UpdateDW(int DWID, int Qdid, string Itemid, string selectionStatus, string ddlSelectedValue, string pgno)
        {
            KPLBasedCommonViewModel kpl = new KPLBasedCommonViewModel();

            kpl.QuoteID           = Qdid;
            kpl.ItemID            = Itemid;
            kpl.DWSelectionStatus = Convert.ToString(DWID);

            return(View("../TCPViews/ItemListView", _iItemListViewService.UpdateDW(kpl, selectionStatus, ddlSelectedValue, Convert.ToInt32(pgno))));
        }
Esempio n. 2
0
        public ActionResult UpdateDWinSingleItemDetailedView(int DWID, int Qdid, string Itemid)
        {
            KPLBasedCommonViewModel kpl = new KPLBasedCommonViewModel();

            kpl.QuoteID           = Qdid;
            kpl.ItemID            = Itemid;
            kpl.DWSelectionStatus = Convert.ToString(DWID);
            IQuoteViewService _QuoteViewSrv = new QuoteViewService();

            ViewData["QuoteTitle"] = _QuoteViewSrv.getQuoteTitleText(Convert.ToInt32(Qdid));
            return(View("../TCPViews/SingleItemDetailedView", _itemservice.UpdateDWSingleItemDetails(kpl)));
        }
Esempio n. 3
0
        public JsonResult UpdateDWSelectionStatus(int DWID, int Qdid, string Itemid, string selectionStatus, string ddlSelectedValue, string pgno)
        {
            KPLBasedCommonViewModel kpl = new KPLBasedCommonViewModel();

            kpl.QuoteID                  = Qdid;
            kpl.ItemID                   = Itemid;
            kpl.DWSelectionStatus        = Convert.ToString(DWID);
            _iItemListViewService.UserVM = UserVM;
            ItemListViewModel itemListVM = _iItemListViewService.UpdateDW(kpl, selectionStatus, ddlSelectedValue, Convert.ToInt32(pgno));

            //  this.AssignUserVM(itemListVM.UserVM);
            return(Json(itemListVM));
        }
        //addToCart,YesNoMayBE,AddToSet
        public ItemListViewModel selectedOptions(string lstiID, string quoteID, int userID, string type = "", int quantity = 0)
        {
            string[] itemList     = lstiID.Split(',');
            int      quoteid      = Convert.ToInt32(quoteID);
            int      currentquote = Convert.ToInt32(quoteID);
            Quote    CurrentQuote = null;

            Quote quoteToUpdate = _Context.Quote.GetSingle(e => e.QuoteID == quoteid);
            User  loggedInUser  = _Context.User.GetSingle(e => e.UserId == userID);
            int   rollID        = loggedInUser.webpages_Roles.FirstOrDefault().RoleId;

            if ((rollID == (int)UserRolesEnum.Repo || rollID == (int)UserRolesEnum.AdminRep) && CurrentQuote == null)
            {
                CurrentQuote = type == "Preview" ? _Context.Quote.GetSingle(e => e.QuoteTypeID == (int)QuoteTypeEnum.ShoppingCart && e.UserID == UserVM.CRMModelProperties.LoggedINCustomerUserID) : _Context.Quote.GetSingle(e => e.QuoteID == quoteid);
            }
            else if ((rollID == (int)UserRolesEnum.CustomerShipTo) && CurrentQuote == null)
            {
                CurrentQuote = _Context.Quote.GetSingle(e => e.QuoteTypeID == (int)QuoteTypeEnum.ShoppingCart && e.UserID == UserVM.CRMModelProperties.LoggedINCustomerUserID);
            }
            int dwselectionID = CurrentQuote.QuoteType.QuoteTypeID == (int)QuoteTypeEnum.ShoppingCart ? (int)DecisionWhizardStatusEnum.Yes : (int)DecisionWhizardStatusEnum.New;
            List <KPLBasedCommonViewModel> lstKplViewModel = new List <KPLBasedCommonViewModel>();
            List <string> lstitemIdsToUI = new List <string>();

            _Context.Quote.SetAutoDetectChangesEnabled(false);

            foreach (string Itemid in itemList)
            {
                if (Itemid != "")
                {
                    KPLBasedCommonViewModel tempKplViewModel = new KPLBasedCommonViewModel();
                    // int itemNum = Convert.ToInt32(Itemid);
                    QuoteDetail quoteDetail         = CurrentQuote.QuoteDetails.Where(e => e.ItemID == Itemid).FirstOrDefault();
                    QuoteDetail quoteDetailToUpdate = null;
                    if (quoteid != 0)
                    {
                        quoteDetailToUpdate = quoteToUpdate.QuoteDetails.SingleOrDefault(e => e.ItemID == Itemid);
                    }
                    if (quoteDetail == null || (quoteDetail.DWSelectionID != (int)DecisionWhizardStatusEnum.Yes) && (quoteDetail.DWSelectionID != (int)DecisionWhizardStatusEnum.New))
                    {
                        lstitemIdsToUI.Add(Itemid);
                    }
                    if (quoteDetail == null)
                    {
                        _Context.QuoteDetail.Add(new QuoteDetail
                        {
                            ItemID        = Itemid,
                            QuoteID       = CurrentQuote.QuoteID,
                            DWSelectionID = dwselectionID,
                            Quantity      = quantity == 0 ? 1 : quantity,
                            CreatedDate   = System.DateTime.Now,
                            UpdateDate    = System.DateTime.Now
                        });
                    }

                    //Updating Penworthy Updated Date
                    if (quoteDetailToUpdate != null)
                    {
                        quoteDetailToUpdate.DWSelectionID = dwselectionID;
                        quoteDetailToUpdate.UpdateDate    = System.DateTime.Now;
                    }
                    if (quoteDetail != null)
                    {
                        quoteDetail.DWSelectionID = dwselectionID;
                        quoteDetail.UpdateDate    = System.DateTime.Now;
                        // quoteDetail.Quantity = 1;
                    }
                    if (rollID == (int)UserRolesEnum.Repo || rollID == (int)UserRolesEnum.AdminRep)
                    {
                        CurrentQuote.PenworthyUpdatedDate = System.DateTime.UtcNow;
                    }
                    else if (rollID == (int)UserRolesEnum.CustomerShipTo)
                    {
                        CurrentQuote.CustomerUpdatedDate = System.DateTime.UtcNow;
                    }
                    CurrentQuote.UpdateDate = System.DateTime.UtcNow;
                }
            }
            _Context.Quote.SetAutoDetectChangesEnabled(true);
            _Context.Quote.SaveChanges();

            lstKplViewModel.AddRange(_Context.Item.GetAll(e => lstitemIdsToUI.Contains(e.ItemID)).Select(item => new KPLBasedCommonViewModel()
            {
                ItemID      = item.ItemID,
                ISBN        = item.ISBN,
                Price       = item.Price,
                Series      = item.SeriesAndCharacter1 == null ? string.Empty : item.SeriesAndCharacter1.SCText,
                Title       = item.Title,
                Author      = item.Author == null ? string.Empty : item.Author.AuthorName,
                Lexile      = item.Lexile,
                ARLevel     = item.ARLevel,
                RCLevel     = item.RCLevel,
                ProductLine = item.ProductLine.Trim(),
                DWDate      = string.Format("{0:MM/dd/yy}", System.DateTime.UtcNow)
            }).ToList());

            ItemListViewModel itemListVm = new ItemListViewModel();

            itemListVm.KPLItemListVM = lstKplViewModel;
            if (quoteToUpdate != null)
            {
                itemListVm.noOfYesCount =
                    quoteToUpdate.QuoteDetails.Where(e => e.DWSelectionID == (int)DecisionWhizardStatusEnum.Yes)
                    .Sum(e => e.Quantity);
                itemListVm.noOfNoCount =
                    quoteToUpdate.QuoteDetails.Where(e => e.DWSelectionID == (int)DecisionWhizardStatusEnum.No)
                    .Sum(e => e.Quantity);
                itemListVm.noOfMaybeCount =
                    quoteToUpdate.QuoteDetails.Where(e => e.DWSelectionID == (int)DecisionWhizardStatusEnum.MayBe)
                    .Sum(e => e.Quantity);
                itemListVm.noOfNewCount =
                    quoteToUpdate.QuoteDetails.Where(e => e.DWSelectionID == (int)DecisionWhizardStatusEnum.New)
                    .Sum(e => e.Quantity);
                itemListVm.YesTotalPrice = (decimal)quoteToUpdate.QuoteDetails.Where(e => e.DWSelectionID == (int)DecisionWhizardStatusEnum.Yes).Sum(e => e.Item.Price);
            }
            itemListVm.SelectionCount = itemListVm.noOfYesCount + itemListVm.noOfNoCount + itemListVm.noOfMaybeCount + itemListVm.noOfNewCount;
            itemListVm.SCItemsCount   = CurrentQuote.QuoteDetails.Where(e => e.DWSelectionID == (int)DecisionWhizardStatusEnum.Yes).Sum(e => e.Quantity);
            string  taxschuduleID = CurrentQuote.User.Customer != null ? CurrentQuote.User.Customer.TaxScheduleID : null;
            decimal SalesTax      = 0;

            if (string.IsNullOrEmpty(taxschuduleID) || taxschuduleID == "NONTAX")
            {
                SalesTax = 0;
            }
            else
            {
                SalesTax = Convert.ToDecimal(_Context.TaxSchedule.GetSingle(e => e.TaxScheduleID == taxschuduleID).TaxRate);
            }
            decimal?price = CurrentQuote.QuoteDetails.Where(e => e.DWSelectionID == (int)DecisionWhizardStatusEnum.Yes).Sum(e => e.Quantity * e.Item.Price);

            itemListVm.SCItemsPrice = price + (price * SalesTax);

            itemListVm.ItemIDS = lstiID;
            UserVM.SCCount     = itemListVm.SCItemsCount;
            UserVM.SCPrice     = itemListVm.SCItemsPrice;
            return(itemListVm);
        }
        //Update the DWStatus in SingleItemDetailedView
        public SingleItemDetailedModel UpdateDWSingleItemDetails(KPLBasedCommonViewModel itemViewModel)
        {
            #region Private Variables
            int currentDWStatus = Convert.ToInt32(itemViewModel.DWSelectionStatus);
            int DWYes           = (int)DecisionWhizardStatusEnum.Yes;
            int DWNo            = (int)DecisionWhizardStatusEnum.No;
            int DWMayBe         = (int)DecisionWhizardStatusEnum.MayBe;

            #endregion
            QuoteDetail dwquoteDetail = new QuoteDetail();

            Quote scQuote = _Context.Quote.GetSingle(e => e.QuoteTypeID == (int)QuoteTypeEnum.ShoppingCart && e.UserID == UserVM.CRMModelProperties.LoggedINCustomerUserID);
            Quote DWQuote = _Context.Quote.GetSingle(e => e.QuoteTypeID == (int)QuoteTypeEnum.DecisionWhizard && e.UserID == UserVM.CRMModelProperties.LoggedINCustomerUserID);
            List <QuoteDetail> lstSCQuoteDetails = scQuote.QuoteDetails.ToList();
            if (lstSCQuoteDetails != null)//item is in shoppingcart
            {
                QuoteDetail scQuoteDetail = lstSCQuoteDetails.Where(e => e.ItemID == itemViewModel.ItemID).FirstOrDefault();
                dwquoteDetail = _Context.QuoteDetail.GetSingle(e => e.QuoteID == itemViewModel.QuoteID && e.ItemID == itemViewModel.ItemID);
                if (scQuoteDetail != null)
                {
                    if (currentDWStatus == DWNo || currentDWStatus == DWMayBe)
                    {
                        //delete from sc
                        _Context.QuoteDetail.Delete(scQuoteDetail);
                    }
                }
                else
                {
                    if (currentDWStatus == DWYes)
                    {
                        //Insert In to Sc
                        _Context.QuoteDetail.Add(new QuoteDetail
                        {
                            ItemID        = itemViewModel.ItemID,
                            Quantity      = 1,
                            CreatedDate   = DateTime.Now,
                            QuoteID       = scQuote.QuoteID,
                            DWSelectionID = (int)DecisionWhizardStatusEnum.Yes,
                            UpdateDate    = DateTime.Now
                        });
                        //Insert In to DW
                        if (dwquoteDetail == null)
                        {
                            _Context.QuoteDetail.Add(new QuoteDetail
                            {
                                ItemID        = itemViewModel.ItemID,
                                Quantity      = 1,
                                CreatedDate   = DateTime.Now,
                                QuoteID       = DWQuote.QuoteID,
                                DWSelectionID = (int)DecisionWhizardStatusEnum.Yes,
                                UpdateDate    = DateTime.Now
                            });
                        }
                    }
                }
                if (dwquoteDetail != null)
                {
                    dwquoteDetail.DWSelectionID = Convert.ToInt32(itemViewModel.DWSelectionStatus);
                }
            }

            _Context.QuoteDetail.SaveChanges();

            //To get next element in list when we select either of yes no may be in singleItemDetailedview
            List <QuoteDetail> quoteDetailList = new List <QuoteDetail>();
            ItemListViewModel  _itemList       = new ItemListViewModel();
            _itemList.KPLItemListVM = new List <KPLBasedCommonViewModel>();
            quoteDetailList         = _Context.QuoteDetail.GetAll(e => e.QuoteID == itemViewModel.QuoteID).ToList();
            List <Item> lstItem = quoteDetailList.Select(e => e.Item).ToList();
            _itemList.KPLItemListVM = AutoMapper.Mapper.Map <IList <Item>, IList <KPLBasedCommonViewModel> >(lstItem).ToList();
            int index = _itemList.KPLItemListVM.FindIndex(e => e.ItemID == itemViewModel.ItemID);
            if (index < _itemList.KPLItemListVM.Count() - 1)
            {
                itemViewModel.ItemID = _itemList.KPLItemListVM[index + 1].ItemID;
            }
            SingleItemDetailedModel singleItemDetailes = GetSingleItemDetailsWithSets(itemViewModel.ItemID.ToString(), itemViewModel.QuoteID.ToString());

            return(singleItemDetailes);
        }