public async Task <Result <DiscountManageModel> > UpdateDiscount([FromBody] DiscountManageModel model)
        {
            if (!Validate(model))
            {
                return(null);
            }
            var discount = await _mapper.FromModelAsync(model);

            var sUserId = _userManager.GetUserId(User);
            int userId;

            if (Int32.TryParse(sUserId, out userId))
            {
                discount.IdEditedBy = userId;
            }
            if (discount.Id > 0)
            {
                var superAdminName = _referenceData.AdminRoles.Single(x => x.Key == (int)RoleType.SuperAdminUser).Text;
                var isSuperAdmin   = HttpContext.User.IsInRole(superAdminName.Normalize());
                discount = await _discountService.UpdateWithSuperAdminCheckAsync(discount, isSuperAdmin);
            }
            else
            {
                discount = await _discountService.InsertAsync(discount);
            }

            return(await _mapper.ToModelAsync <DiscountManageModel>(discount));
        }
        public async Task <Result <DiscountManageModel> > GetDiscount(string id)
        {
            int idProduct = 0;

            if (id != null && !Int32.TryParse(id, out idProduct))
            {
                throw new NotFoundException();
            }

            if (idProduct == 0)
            {
                var now = DateTime.Now;
                now = new DateTime(now.Year, now.Month, now.Day);
                return(new DiscountManageModel()
                {
                    StatusCode = RecordStatusCode.Active,
                    Assigned = CustomerType.Retail,
                    DiscountType = DiscountType.PercentDiscount,
                    StartDate = TimeZoneInfo.ConvertTime(now, TimeZoneHelper.PstTimeZoneInfo, TimeZoneInfo.Local),
                    ExpirationDate = TimeZoneInfo.ConvertTime(now.AddDays(30), TimeZoneHelper.PstTimeZoneInfo, TimeZoneInfo.Local),
                    DiscountsToSelectedSkus = new List <DiscountToSelectedSku>(),
                    DiscountsToSkus = new List <DiscountToSku>(),
                    DiscountTiers = new List <DiscountTier>(),
                    CategoryIds = new List <int>(),
                    CategoryIdsAppliedOnlyTo = new List <int>(),
                });
            }

            var item = await _discountService.SelectAsync(idProduct);

            if (item == null)
            {
                throw new NotFoundException();
            }

            DiscountManageModel toReturn = await _mapper.ToModelAsync <DiscountManageModel>(item);

            return(toReturn);
        }