public async Task <IActionResult> Edit(int id, [Bind("Title, Description, SubjectNameId, Price, SharePriceOption, ImageUrl, Address")] EditOfferViewModel model)
        {
            try
            {
                var offerDto = mapper.Map <EditOfferViewModel, EditOfferDTO>(model);
                offerDto.Id = id;
                var result = await offerService.EditOffer(offerDto);

                var log = new Log
                {
                    UserId       = this.userManager.GetUserId(HttpContext.User),
                    LogType      = LogType.EditedAnOffer,
                    DateTime     = DateTime.Now,
                    ResourceId   = result,
                    ResourceType = ResourceType.Offer
                };
                int logResult = await logService.AddLog(log);

                this.TempData[Constants.ValidationState.Success] = Constants.Message.OfferUpdate.Success;
            }
            catch (Exception ex)
            {
                this.TempData[Constants.ValidationState.Error] = ex.Message;
            }

            return(this.RedirectToAction("Details", id));
        }
Exemple #2
0
        public IHttpActionResult Edit(OfferViewModel offerView)
        {
            try
            {
                offerService.EditOffer(Mapper.Map <OfferViewModel, OfferDTO>(offerView));

                return(Ok("Offer is edited"));
            }
            catch (ArgumentNullException)
            {
                return(BadRequest("Not correct input data"));
            }
            catch (ArgumentOutOfRangeException ex)
            {
                return(BadRequest(ex.ParamName));
            }
        }
Exemple #3
0
 public void EditOffer_PutInEditNullElement_ShouldThrowException()
 {
     // act & assert
     NUnit.Framework.Assert.Throws <ArgumentNullException>(() => offerService.EditOffer(null));
 }
        public async Task <ActionResult> EditOffer([FromBody] OfferViewModel offer)
        {
            var dto = await _offerService.EditOffer(offer);

            return(new OkObjectResult(dto));
        }