Beispiel #1
0
        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));
        }
Beispiel #2
0
        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());
        }
Beispiel #3
0
 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);
 }
Beispiel #4
0
        public AwardDto ToAwardDto(Award award)
        {
            var awardDto = new AwardDto()
            {
                Id          = award.Id,
                Title       = award.Title,
                Description = award.Description,
                ImageUrl    = award.Image.Url
            };

            return(awardDto);
        }
Beispiel #5
0
        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));
        }
Beispiel #6
0
        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));
        }
Beispiel #7
0
        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));
        }
Beispiel #8
0
        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));
        }
Beispiel #9
0
 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());
     }
 }
Beispiel #10
0
        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));
        }
Beispiel #11
0
        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);
        }
Beispiel #12
0
 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());
     }
 }
Beispiel #13
0
        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);
        }
Beispiel #14
0
 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);
 }