Exemple #1
0
        public Control view()
        {
            Control v = new PricingView();

            v.DataContext = this;
            return(v);
        }
        public IActionResult Upsert(int?id)
        {
            // string userId = User.Identity.GetUserId();
            var userId = User.FindFirstValue(ClaimTypes.NameIdentifier);// will give the user's userId

            PricingView pricingVM = new PricingView();

            if (id == null)
            {
                return(NotFound());
            }
            else
            {
                Product product = _unitOfWork.Product.Get(id.GetValueOrDefault());
                if (product == null)
                {
                    return(NotFound());
                }
                pricingVM.PricingHistory = new PricingHistory()
                {
                    Id         = 0,
                    ProductId  = product.Id,
                    OPrice     = product.Price,
                    NPrice     = product.Price,
                    UpdateDate = DateTime.Now,
                    UserId     = userId
                };
                pricingVM.ProductName = product.Name;

                //Get Histroy Prcing include the UserInfo
                //   pricingVM.PricingHistoryLst = _unitOfWork.PricingHistory.GetByProduct(product.Id);
            }

            return(View(pricingVM));
        }
 public IActionResult Upsert(PricingView pricingVM)
 {
     if (ModelState.IsValid)
     {
         if (pricingVM.PricingHistory.Id == 0)
         {
             Product product = _unitOfWork.Product.Get(pricingVM.PricingHistory.ProductId);
             product.Price = pricingVM.PricingHistory.NPrice;
             pricingVM.PricingHistory.UpdateDate = DateTime.Now;
             _unitOfWork.PricingHistory.Add(pricingVM.PricingHistory);
         }
         else
         {
             //_unitOfWork.PricingHistory.(pricing);
         }
         _unitOfWork.Save();
         return(RedirectToAction(nameof(Upsert)));
     }
     else
     {
         return(View(pricingVM));
     }
 }
 public  Control view()
 {
     Control v = new PricingView();
     v.DataContext = this;
     return v;
 }