Esempio n. 1
0
        public async Task <JsonResult> ChangePrice(Product_PriceModel model)
        {
            var Messaging = new RenderMessaging();

            try
            {
                var pricechannel = _unitOW.ChanelPriceRepository.FindBy(o => o.ProductId == model.ProductId && o.ChannelId == User.ChannelId).FirstOrDefault();
                if (pricechannel != null)
                {
                    if (pricechannel.Price != model.Price)
                    {
                        pricechannel.Price          = Convert.ToInt32(Helpers.Round_Double(model.Price, -3));;
                        pricechannel.DateUpdate     = DateTime.Now;
                        pricechannel.EmployeeUpdate = User.UserId;

                        _unitOW.ChanelPriceRepository.Update(pricechannel, o => o.Price, o => o.DateUpdate, o => o.EmployeeUpdate);

                        await _unitOW.SaveChanges();
                    }
                }
                else
                {
                    var data = new soft_Channel_Product_Price
                    {
                        Price          = Convert.ToInt32(Helpers.Round_Double(model.Price, -3)),
                        ChannelId      = User.ChannelId,
                        ProductId      = model.ProductId,
                        DateCreate     = DateTime.Now,
                        EmployeeCreate = User.UserId
                    };

                    _unitOW.ChanelPriceRepository.Add(data);
                    await _unitOW.SaveChanges();
                }


                #region gia si
                var user    = Mapper.Map <UserCurrent>(User);
                var product = _unitOW.ProductRepository.FindBy(o => o.id == model.ProductId).FirstOrDefault();
                _IOrderBus.UpdatePriceWholesale(product, user, true);
                #endregion

                Messaging.messaging = "Đã thay đổi giá thành công!";
            }
            catch
            {
                Messaging.isError   = true;
                Messaging.messaging = "Thay đổi giá không thành công!";
            }
            return(Json(Messaging, JsonRequestBehavior.AllowGet));
        }
Esempio n. 2
0
        public async Task <JsonResult> ChangePrice_Discount(Product_PriceModel item)
        {
            var Messaging = new RenderMessaging();

            try
            {
                if (User == null || User.UserId < 0)
                {
                    Messaging.isError   = true;
                    Messaging.messaging = "Vui lòng đăng nhập lại!";
                    return(Json(Messaging, JsonRequestBehavior.AllowGet));
                }

                if (item.Price_Discount <= 0)
                {
                    Messaging.messaging = "Giá giảm không hợp lệ!";
                    Messaging.isError   = true;
                }

                if (!item.StartDate_Discount.HasValue ||
                    !item.Enddate_Discount.HasValue ||
                    item.StartDate_Discount.Value > item.Enddate_Discount.Value ||
                    item.StartDate_Discount.Value < DateTime.Now)
                {
                    Messaging.messaging = "Ngày áp dụng không hợp lệ!";;
                    Messaging.isError   = true;
                }

                if (Messaging.isError)
                {
                    return(Json(Messaging, JsonRequestBehavior.AllowGet));
                }


                item.ChannelId          = User.ChannelId;
                item.StartDate_Discount = new DateTime(item.StartDate_Discount.Value.Year, item.StartDate_Discount.Value.Month, item.StartDate_Discount.Value.Day, 0, 0, 0, 0);
                item.Enddate_Discount   = new DateTime(item.Enddate_Discount.Value.Year, item.Enddate_Discount.Value.Month, item.Enddate_Discount.Value.Day, 23, 59, 59, 999);

                var pricechannel = _unitOW.ChanelPriceRepository.FindBy(o => o.ProductId == item.ProductId && o.ChannelId == User.ChannelId).FirstOrDefault();

                if (pricechannel != null)
                {
                    pricechannel.Price_Discount     = Convert.ToInt32(Helpers.Round_Double(item.Price_Discount, -3));
                    pricechannel.StartDate_Discount = item.StartDate_Discount;
                    pricechannel.Enddate_Discount   = item.Enddate_Discount;
                    pricechannel.DateUpdate         = DateTime.Now;
                    pricechannel.EmployeeUpdate     = User.UserId;

                    _unitOW.ChanelPriceRepository.Update(pricechannel,
                                                         o => o.Price_Discount,
                                                         o => o.StartDate_Discount,
                                                         o => o.Enddate_Discount,
                                                         o => o.DateUpdate,
                                                         o => o.EmployeeUpdate);

                    await _unitOW.SaveChanges();
                }
                else
                {
                    var data = new soft_Channel_Product_Price
                    {
                        ChannelId = item.ChannelId,
                        ProductId = item.ProductId,

                        Price_Discount     = Convert.ToInt32(Helpers.Round_Double(item.Price_Discount, -3)),
                        StartDate_Discount = item.StartDate_Discount,
                        Enddate_Discount   = item.Enddate_Discount,

                        DateCreate     = DateTime.Now,
                        EmployeeCreate = User.UserId
                    };
                    _unitOW.ChanelPriceRepository.Add(data);

                    await _unitOW.SaveChanges();
                }

                Messaging.messaging = "Đã thay đổi giá khuyến mãi thành công!";
            }
            catch (Exception ex)
            {
                Messaging.isError   = true;
                Messaging.messaging = "Thay đổi giá khuyến mãi không thành công!";
            }
            return(Json(Messaging, JsonRequestBehavior.AllowGet));
        }