Beispiel #1
0
        /// <summary>
        /// Gets UpsertDiscountRequest entity from Discount entity.
        /// </summary>
        /// <param name="discount"></param>
        /// <returns></returns>
        public static UpsertDiscountRequest ToUpsertDiscountRequest(this Discount discount)
        {
            if (discount.IsEmpty())
            {
                return(null);
            }

            var upsert = new UpsertDiscountRequest
            {
                Id                   = discount.Id,
                Name                 = discount.Name,
                Description          = discount.Description,
                AmountOfDiscount     = discount.AmountOfDiscount,
                StartDate            = discount.StartDate,
                EndDate              = discount.EndDate,
                Address              = discount.Address,
                Company              = discount.Company,
                WorkingDaysOfTheWeek = discount.WorkingDaysOfTheWeek,
                Tags                 = discount.Tags,
                PictureUrl           = discount.PictureUrl,
                Language             = discount.Language,
                Translations         = discount.Translations,
                PromocodeOptions     = discount.PromocodeOptions
            };

            return(upsert);
        }
Beispiel #2
0
 /// <summary>
 /// Gets Discount entity from UpsertDiscountRequest entity.
 /// </summary>
 /// <param name="upsertDiscountRequest"></param>
 /// <returns></returns>
 public static Discount ToDiscount(this UpsertDiscountRequest upsertDiscountRequest)
 {
     return(new()
     {
         Id = upsertDiscountRequest.Id,
         Name = upsertDiscountRequest.Name,
         Description = upsertDiscountRequest.Description,
         AmountOfDiscount = upsertDiscountRequest.AmountOfDiscount,
         StartDate = upsertDiscountRequest.StartDate,
         EndDate = upsertDiscountRequest.EndDate,
         Address = upsertDiscountRequest.Address,
         Company = upsertDiscountRequest.Company,
         WorkingDaysOfTheWeek = upsertDiscountRequest.WorkingDaysOfTheWeek,
         Tags = upsertDiscountRequest.Tags,
         PictureUrl = upsertDiscountRequest.PictureUrl,
         Language = upsertDiscountRequest.Language,
         Translations = upsertDiscountRequest.Translations,
         PromocodeOptions = upsertDiscountRequest.PromocodeOptions
     });
 }
        public async Task <IActionResult> UpsertDiscount([FromBody, CustomizeValidator(RuleSet = "UpsertDiscount")] UpsertDiscountRequest upsertDiscountRequest)
        {
            var currentUser = ControllerContext.CurrentUser();
            var user        = (await _users.GetUserByUidAsync(currentUser.Id)).ToUserLikeEmployee();

            var discount = upsertDiscountRequest.ToDiscount().AddChangeUserTime(user);

            var responseDiscount = await _discounts.UpsertDiscountAsync(discount);

            if (responseDiscount.IsEmpty())
            {
                _logger.LogWarning("Upsert Discount. UpsertDiscountRequest: {@upsertDiscountRequest}. Result is Empty. User: {@currentUser}.", upsertDiscountRequest, currentUser);
                return(BadRequest("No discounts were create or update."));
            }

            var response = responseDiscount.ToUpsertDiscountRequest();

            _logger.LogInformation("Upsert Discount. UpsertDiscountRequest: {@upsertDiscountRequest}. Result: {@response}. User: {@currentUser}.", upsertDiscountRequest, response, currentUser);
            return(Ok(response));
        }