public ActionResult <IEnumerable <BonusDto> > AddServiceBonus(BonusDto bonusDto)
        {
            Bonus bonusMap = _mapper.Map <Bonus>(bonusDto);

            _serviceService.AddServiceBonus(bonusMap);

            BonusDto bonusDtoMap = _mapper.Map <BonusDto>(bonusMap);

            IEnumerable <Bonus> getBonus = _serviceService.GetServiceBonusById(bonusDtoMap.BonusId);

            return(Ok(getBonus));
        }
예제 #2
0
 public ActionResult <BonusDto> Put([FromBody] BonusDto model)
 {
     try
     {
         var updatedBonus = _bonusRepository.UpdateBonus(model);
         return(Ok(updatedBonus));
     }
     catch (Exception ex)
     {
         return(StatusCode(StatusCodes.Status304NotModified, new Response {
             Success = false, Message = ex.Message
         }));
     }
 }
예제 #3
0
        // 我的盈亏情况
        // GET: /Casino/Bonus

        public ActionResult MyBonus(Criteria criteria)
        {
            var model = new MyBonusDto();

            var query = _repo.Query <BonusView>(criteria, x => x.UserID == AcnID);

            var mapper = BonusDto.ConfigMapper().CreateMapper();

            var list = mapper.Map <IEnumerable <BonusDto> >(query.AsEnumerable());

            model.Criteria = criteria;
            model.Data     = list;

            return(View(model));
        }
        public BonusDto UpdateBonus(BonusDto model)
        {
            try
            {
                var bonus = context.Bonuses.Find(model.JobDescriptionId);
                bonus.BonusName = model.BonusName;
                bonus.Amount    = model.Amount;
                context.Bonuses.Update(bonus);
                context.SaveChanges();

                return(mapper.Map <BonusDto>(bonus));
            }
            catch (Exception)
            {
                throw; // new Exception("The update was not successful");
            }
        }
        public async Task <IEnumerable <BonusDto> > GetAllBonusAsync()
        {
            var listOfBonuses = await context.Bonuses.Include(s => s.JobDescription).Include(s => s.Department).ToListAsync();

            var listofBonusDto = new List <BonusDto>();

            foreach (var item in listOfBonuses)
            {
                var bonusDto = new BonusDto
                {
                    BonusName          = item.BonusName,
                    Amount             = item.Amount,
                    JobDescriptionName = item.JobDescription.JobDescriptionName,
                    DepartmentName     = item.Department.DepartmentName
                };
                listofBonusDto.Add(bonusDto);
            }
            return(listofBonusDto);
        }
예제 #6
0
        public async Task <ActionResult <BonusDto> > Post([FromBody] BonusDto model)
        {
            try
            {
                var createdBonus = await _bonusRepository.AddBonusAsync(model);

                var location = _linkGenerator.GetPathByAction("GetBonusByID", "Bonus", new { id = model.JobDescriptionId });
                if (string.IsNullOrWhiteSpace(location))
                {
                    return(BadRequest($"The URI was not found"));
                }
                return(Created(location, createdBonus));
            }
            catch (Exception ex)
            {
                return(BadRequest(new Response {
                    Success = false, Message = ex.Message
                }));
            }
        }
        public async Task <BonusDto> GetBonusById(int id)
        {
            try
            {
                var getBonusById = await context.Bonuses.Where(s => s.JobDescriptionId == id).FirstOrDefaultAsync();

                if (getBonusById is not null)
                {
                    var bonusDto = new BonusDto
                    {
                        BonusName = getBonusById.BonusName,
                        Amount    = getBonusById.Amount
                    };
                    return(bonusDto);
                }
                throw new ArgumentNullException(getBonusById.BonusName);
            }
            catch (Exception)
            {
                throw new Exception();
            }
        }
예제 #8
0
        public IEnumerable <BonusDto> GetTestBonuses(List <EmployeeDto> employees)
        {
            var bonuses = new List <BonusDto>();

            var random       = new Random();
            var total        = employees.Count();
            var totalBonuses = total * 0.4;

            for (var i = 0; i < totalBonuses; i++)
            {
                var employeeIndex = random.Next(0, total);
                var bonusAmount   = random.Next(1, 20) * 1000M;
                var bonusDate     = DateTime.Now.AddDays(random.Next(0, 180) * -1);
                var bonus         = new BonusDto
                {
                    Employee    = employees[employeeIndex],
                    BonusDate   = bonusDate,
                    BonusAmount = bonusAmount
                };
                bonuses.Add(bonus);
            }

            return(bonuses);
        }
        public async Task <BonusDto> AddBonusAsync(BonusDto model)
        {
            try
            {
                var bonus = new Bonus
                {
                    BonusName = model.BonusName,
                    Amount    = model.Amount,
                };

                var bonusentity = await context.AddAsync(bonus);

                await context.SaveChangesAsync();

                var a = bonusentity.Entity;
                model.BonusName = a.BonusName;
                model.Amount    = a.Amount;
                return(model);
            }
            catch (Exception)
            {
                throw; // new Exception("The process was not successful");
            }
        }
예제 #10
0
        public async Task <IActionResult> SetBonus([FromBody] BonusDto dto)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest());
            }

            try
            {
                string userId   = User.Claims.First(c => c.Type == "UserID").Value;
                string userRole = User.Claims.First(c => c.Type == "Roles").Value;
                var    user     = await unitOfWork.UserManager.FindByIdAsync(userId);

                if (!userRole.Equals("Admin"))
                {
                    return(Unauthorized());
                }

                if (user == null)
                {
                    return(NotFound("User not found"));
                }

                if (dto.Bonus < 0 || dto.Discount < 0 || dto.Discount > 100)
                {
                    return(BadRequest("Inputs are not valid"));
                }

                var bonus = await unitOfWork.BonusRepository.GetByID(1);

                if (bonus == null)
                {
                    bonus = new Bonus()
                    {
                        BonusPerKilometer      = dto.Bonus,
                        DiscountPerReservation = dto.Discount
                    };

                    try
                    {
                        await unitOfWork.BonusRepository.Insert(bonus);

                        await unitOfWork.Commit();
                    }
                    catch (Exception)
                    {
                        return(StatusCode(500, "Transaction failed"));
                    }
                    return(Ok());
                }

                bonus.BonusPerKilometer      = dto.Bonus;
                bonus.DiscountPerReservation = dto.Discount;

                try
                {
                    unitOfWork.BonusRepository.Update(bonus);
                    await unitOfWork.Commit();
                }
                catch (Exception)
                {
                    return(StatusCode(500, "Transaction failed"));
                }

                return(Ok());
            }
            catch (Exception)
            {
                return(StatusCode(500, "Failed to set bonus"));
            }
        }