public AdvertistmentViewModel Add(AdvertistmentViewModel AdvertistmentVm) { var Advertistment = Mapper.Map <AdvertistmentViewModel, Advertistment>(AdvertistmentVm); _advertistmentRepository.Add(Advertistment); return(AdvertistmentVm); }
public async Task <IActionResult> Update([FromBody] AdvertistmentViewModel advertistmentVm) { var hasPermission = await _authorizationService.AuthorizeAsync(User, "ADVERTISMENT", Operations.Update); if (hasPermission.Succeeded == false) { return(new BadRequestObjectResult(CommonConstants.Forbidden)); } if (ModelState.IsValid) { try { Advertistment advertistmentDb = _advertistmentService.DetailDb(advertistmentVm.Id); string oldPath = advertistmentDb.Image; if (oldPath != advertistmentVm.Image && !string.IsNullOrEmpty(oldPath)) { oldPath.DeletementByString(_env); } advertistmentDb.UpdateAdvertistment(advertistmentVm); _advertistmentService.UpdateDb(advertistmentDb); _advertistmentService.SaveChanges(); return(new OkObjectResult(advertistmentVm)); } catch (Exception ex) { return(new BadRequestObjectResult(ex.Message)); } } return(new BadRequestObjectResult(ModelState)); }
public static void UpdateAdvertistment(this Advertistment advertistment, AdvertistmentViewModel advertistmentVm) { advertistment.Name = advertistmentVm.Name; advertistment.Description = advertistmentVm.Description; advertistment.Image = advertistmentVm.Image; advertistment.Url = advertistmentVm.Url; advertistment.PositionId = advertistmentVm.PositionId; advertistment.PageId = advertistmentVm.PageId; advertistment.Status = advertistmentVm.Status; advertistment.DateModified = DateTime.Now; advertistment.SortOrder = advertistmentVm.SortOrder; }
public Advertistment(AdvertistmentViewModel advertistmentVm) { Name = advertistmentVm.Name; Description = advertistmentVm.Description; Image = advertistmentVm.Image; Url = advertistmentVm.Url; PositionId = advertistmentVm.PositionId; PageId = advertistmentVm.PageId; Status = advertistmentVm.Status; DateModified = DateTime.Now; SortOrder = advertistmentVm.SortOrder; }
public async Task <IActionResult> Add([FromBody] AdvertistmentViewModel advertistmentVm) { var hasPermission = await _authorizationService.AuthorizeAsync(User, "ADVERTISMENT", Operations.Create); if (hasPermission.Succeeded == false) { return(new BadRequestObjectResult(CommonConstants.Forbidden)); } if (ModelState.IsValid) { try { advertistmentVm.DateCreated = DateTime.Now; _advertistmentService.Add(advertistmentVm); _advertistmentService.SaveChanges(); return(new OkObjectResult(advertistmentVm)); } catch (Exception ex) { return(new BadRequestObjectResult(ex.Message)); } } return(new BadRequestObjectResult(ModelState)); }
public void Update(AdvertistmentViewModel product) { throw new NotImplementedException(); }
public void Add(AdvertistmentViewModel advertistmentVm) { _advertistmentRepository.Add(_mapper.Map <Advertistment>(advertistmentVm)); }