public IActionResult Post([FromBody] PBSubscriptionsViewModel viewModel) { try { if (viewModel == null) { return(BadRequest()); } if (!ModelState.IsValid) { return(BadRequest(ModelState)); } PBSubscriptions item = Mapper.Map <PBSubscriptions>(viewModel); item.CreatedDate = DateTime.Now; item.LastUpdatedDate = DateTime.Now; item.IsActive = true; _pbSubscriptionsRepository.Add(item); int save = _pbSubscriptionsRepository.Save(); if (save > 0) { return(CreatedAtRoute("GetById", new { controller = "PBSubscriptions", id = item.Id }, item)); } return(BadRequest()); } catch (Exception exception) { //Do something with the exception return(StatusCode((int)HttpStatusCode.InternalServerError)); } }
public IActionResult Put(int id, [FromBody] PBSubscriptionsViewModel viewModel) { try { if (viewModel == null) { return(BadRequest()); } if (!ModelState.IsValid) { return(BadRequest(ModelState)); } PBSubscriptions singleById = _pbSubscriptionsRepository.GetById(id); if (singleById == null) { return(NotFound()); } singleById.PBNo = viewModel.PBNo; singleById.MSISDN = viewModel.MSISDN; singleById.Keyword = viewModel.Keyword; singleById.SubStartedDate = viewModel.SubStartedDate; singleById.PrizeDate = viewModel.PrizeDate; singleById.LastUpdatedBy = viewModel.LastUpdatedBy; singleById.LastUpdatedDate = DateTime.Now; _pbSubscriptionsRepository.Update(singleById); int save = _pbSubscriptionsRepository.Save(); if (save > 0) { return(Ok(Mapper.Map <PBSubscriptionsViewModel>(singleById))); } return(BadRequest()); } catch (Exception exception) { //Do something with the exception return(StatusCode((int)HttpStatusCode.InternalServerError)); } }