public async Task <IHttpActionResult> PutAward(int id, AwardDto awardDto) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != awardDto.ID) { return(BadRequest()); } var award = DtoToEntityIMapper.Map <AwardDto, Award>(awardDto); //// UoW.GetRepository <Award>().ModifyEntityState(award); try { await UoW.SaveAsync(); } catch (DbUpdateConcurrencyException) { if (!AwardExists(id)) { return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); }
public async Task <ActionResult <AwardDto> > PutAward([FromRoute] int id, [FromBody] AwardDto awardDto) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != awardDto.ID) { return(BadRequest()); } Award award = DtoToEntityIMapper.Map <AwardDto, Award>(awardDto); repository.ModifyEntryState(award, EntityState.Modified); try { await uoW.SaveAsync(); } catch (DbUpdateConcurrencyException) { if (!AwardExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public bool InsertAward(AwardDto award) { return(_context.Awards.Add(new Award { UserId = award.UserId, Title = award.Title, Level = award.Level, IssuedBy = award.IssuedBy, IssuedDate = award.IssuedDate, CreateDate = DateTime.Now }) != null); }
public AwardDto ToAwardDto(Award award) { var awardDto = new AwardDto() { Id = award.Id, Title = award.Title, Description = award.Description, ImageUrl = award.Image.Url }; return(awardDto); }
public async Task <IHttpActionResult> PostAward(AwardDto awardDto) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var award = DtoToEntityIMapper.Map <AwardDto, Award>(awardDto); //// UoW.GetRepository <Award>().Insert(award); await UoW.SaveAsync(); return(CreatedAtRoute("DefaultApi", new { id = award.ID }, award)); }
private bool AddAward(string userId, AwardViewModel award) { var addRecord = new AwardDto() { UserId = userId, Title = award.Title, Level = award.Level, IssuedBy = award.IssuedBy, IssuedDate = award.IssuedDate }; return(_awardService.InsertAward(userId, addRecord)); }
public async Task <ActionResult <AwardDto> > PostAward([FromBody] AwardDto awardDto) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } Award award = DtoToEntityIMapper.Map <AwardDto, Award>(awardDto); repository.Add(award); await uoW.SaveAsync(); return(CreatedAtAction("GetAward", new { id = award.ID }, awardDto)); }
private bool UpdateAward(string userId, AwardViewModel award) { var updateRecord = new AwardDto() { Id = award.Id, UserId = userId, Title = award.Title, Level = award.Level, IssuedBy = award.IssuedBy, IssuedDate = award.IssuedDate }; return(_awardService.UpdateAward(userId, updateRecord)); }
public IHttpActionResult DeactivateRecognitionAward(int?awardId, AwardDto deactivateAwardsDto) { if (deactivateAwardsDto != null) { using (var context = new Entities()) { var result = context.Award_Deactivate( deactivateAwardsDto.Award_Id); return(this.Ok()); } } else { return(this.NotFound()); } }
public async Task <ActionResult <AwardDto> > GetAward([FromRoute] int id) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var award = await repository.GetAsync(a => a.ID == id); if (award == null) { return(NotFound()); } AwardDto awardDto = EntityToDtoIMapper.Map <Award, AwardDto>(award); return(Ok(awardDto)); }
public bool UpdateAward(AwardDto award) { var record = _context.Awards.FirstOrDefault(x => x.Id == award.Id); if (record == null) { return(false); } record.Title = award.Title; record.Level = award.Level; record.IssuedBy = award.IssuedBy; record.IssuedDate = award.IssuedDate; _context.Awards.AddOrUpdate(record); return(_context.SaveChanges() == 1); }
public IHttpActionResult UpdateRedemptionCodeDetail(int awardId, AwardDto recognitionDto) { if (recognitionDto != null) { using (var context = new Entities()) { var result = context.Award_Redeem( recognitionDto.RedeemedOn, recognitionDto.RedemptionLocation, recognitionDto.RedemptionComment, recognitionDto.Award_Id); return(this.Ok()); } } else { return(this.NotFound()); } }
public bool UpdateAward(string userId, AwardDto award) { try { //Validate user if (_userRepository.IsAuthenticated(userId)) { var record = _awardRepository.GetAwardById(award.Id.ToString()); if (record != null) { //Validate Model ICollection <ValidationResult> results; if (IsValidModel(award, out results)) { if (ModelCompareChecker.Compare(award, record)) { return(true); } record.Title = award.Title; record.Level = award.Level; record.IssuedBy = award.IssuedBy; record.IssuedDate = award.IssuedDate; return(_awardRepository.UpdateAward(record)); } _loggingService.Info("Model Validation Failed: " + award); } } _loggingService.Info("UserId Authenticated Failed: " + userId); } catch (Exception ex) { //Error _loggingService.Error("An error has occurred", ex); } //Fail return(false); }
public bool InsertAward(string userId, AwardDto award) { try { //Validate user if (_userRepository.IsAuthenticated(userId)) { //Validate Model ICollection <ValidationResult> results; if (IsValidModel(award, out results)) { //Call Repository if (_awardRepository.InsertAward(award)) { //Save if (_awardRepository.Save()) { //Success return(true); } _loggingService.Info("Failed To Save"); } _loggingService.Info("UserRepository Failed Insert"); } _loggingService.Info("Model Validation Failed: " + award); } _loggingService.Info("UserId Authenticated Failed: " + userId); } catch (Exception ex) { //Error _loggingService.Error("An error has occurred", ex); } //Fail return(false); }