public async Task <DepositMoneyResponse> DepositMoney(DepositMoneyRequest request) { //Check Amount var upperLimit = (await _paramService.FindById(GlobalParams.ParamDepositMoneyUpperLimit)).Value; var lowerLimit = (await _paramService.FindById(GlobalParams.ParamDepositMoneyLowerLimit)).Value; var step = (await _paramService.FindById(GlobalParams.ParamDepositMoneyStep)).Value; if (request.Amount > upperLimit || request.Amount < lowerLimit || (request.Amount / step) > GlobalParams.AcceptableDecimalMistake) { throw new HttpStatusCodeException(HttpStatusCode.BadRequest, "amount must be between " + lowerLimit + " and " + upperLimit + " and must be multiple of " + step); } //Find student in database var student = await _studentService.FindById(request.StudentId); var originalBalance = student.AccountBalance; //Change student's balance student.AccountBalance += request.Amount; var resultBalance = student.AccountBalance; //Update information in database student = await _repoWrapper.Student.UpdateAsync(student, student.StudentId); //Create MoneyTransaction entity var moneyTransaction = DepositMoneyRequest.EntityFromRequest(originalBalance, resultBalance, request); //Create MoneyTransaction in database moneyTransaction = await _repoWrapper.MoneyTransaction.CreateAsync(moneyTransaction); //Return View Model return(DepositMoneyResponse.ResponseFromModel(moneyTransaction)); }
public async Task <ArrangeRoomResponseStudent> ApproveRoomBookingRequest(int id) { var roomBooking = await FindById(id); //Check if room request if (roomBooking.Status != RequestStatus.Pending) { throw new HttpStatusCodeException(HttpStatusCode.Forbidden, "RoomService: Request is not a pending request"); } //Get student by id in room booking var student = await _repoWrapper.Student.FindByIdAsync(roomBooking.StudentId); if (student == null) { throw new HttpStatusCodeException(HttpStatusCode.NotFound, "RoomService: Student not found"); } //Get active room with appropriate gender sorted by ascending room vacancy var rooms = await _repoWrapper.Room.GetAllActiveRoomWithSpecificGenderAndRoomTypeSortedByVacancy(student.Gender, roomBooking.TargetRoomType); if (rooms == null || !rooms.Any()) { throw new HttpStatusCodeException(HttpStatusCode.NotFound, "RoomService: Suitable Room not found"); } var room = rooms[0]; //Attach room's id to student student.RoomId = room.RoomId; student.IsHold = true; room.CurrentNumberOfStudent++; roomBooking.Status = RequestStatus.Approved; var maxDayForCompleteRoomBooking = await _paramService.FindById(GlobalParams.MaxDayForCompleteRoomBooking); if (maxDayForCompleteRoomBooking?.Value == null) { throw new HttpStatusCodeException(HttpStatusCode.NotFound, "RoomService: MaxDayForCompleteRoomBooking not found"); } var rejectDate = DateHelper.AddBusinessDays(DateTime.Now.AddHours(GlobalParams.TimeZone), maxDayForCompleteRoomBooking.Value.Value); roomBooking.RejectDate = new DateTime(rejectDate.Year, rejectDate.Month, rejectDate.Day, 17, 59, 0); await _repoWrapper.Student.UpdateAsyncWithoutSave(student, student.StudentId); await _repoWrapper.Room.UpdateAsyncWithoutSave(room, room.RoomId); await _repoWrapper.RoomBooking.UpdateAsyncWithoutSave(roomBooking, roomBooking.RoomBookingRequestFormId); await _repoWrapper.Save(); return(ArrangeRoomResponseStudent.ResponseFromEntity(student, room, roomBooking)); }
public async Task <CreateEquipmentResponse> CreateEquipment(CreateEquipmentRequest requestModel) { //If there's a room, check if the room exists if (requestModel.RoomId != null) { var room = await _room.FindById(requestModel.RoomId.Value); } //Check if equipment type is valid var equipmentType = await _param.FindById(requestModel.EquipmentTypeId); if (equipmentType.ParamTypeId != GlobalParams.ParamTypeEquipmentType) { throw new HttpStatusCodeException(HttpStatusCode.BadRequest, "EquipmentService: EquipmentType is not Valid"); } var equipment = await _repoWrapper.Equipment.CreateAsync( CreateEquipmentRequest.NewEquipmentFromRequest(requestModel, equipmentType.TextValue)); equipment.Code += equipment.EquipmentId; equipment = await _repoWrapper.Equipment.UpdateAsync(equipment, equipment.EquipmentId); return(CreateEquipmentResponse.CreateFromEquipment(equipment)); }
public async Task <GetIssueTicketDetailResponse> GetIssueTicketDetail(int id) { var issueTicket = await FindById(id); var owner = await _studentService.FindById(issueTicket.OwnerId); // Student targetStudent = null; // // if (issueTicket.TargetStudentId != null) // { // targetStudent = await _studentService.FindById(issueTicket.TargetStudentId.Value); // } var type = await _paramService.FindById(issueTicket.Type); return(GetIssueTicketDetailResponse.ResponseFromEntity(issueTicket, owner, type)); }
public async Task <SendRenewContractRequestResponse> SendRenewContract(SendRenewContractRequestRequest request) { var acceptableMonths = (await _paramService.FindAllByParamType(GlobalParams.ParamTypeContractParam)).Select(p => p.Value).ToList(); if (!acceptableMonths.Contains(request.Month)) { throw new HttpStatusCodeException(HttpStatusCode.Forbidden, "RenewContractService: Month is invalid"); } var student = await _studentService.FindById(request.StudentId); //Check if student has room if (student.RoomId == null) { throw new HttpStatusCodeException(HttpStatusCode.Forbidden, "RenewContractService: Student doesn't have room"); } //Check student's evaluation point is enough var contractRenewalEvaluationScoreMargin = (await _paramService.FindById(GlobalParams.ParamContractRenewalEvaluationPointMargin))?.Value ?? GlobalParams.DefaultContractRenewalEvaluationPointMargin; if (student.EvaluationScore < contractRenewalEvaluationScoreMargin) { throw new HttpStatusCodeException(HttpStatusCode.Forbidden, "RenewContractService: Student's evaluation is not enough"); } var contracts = (List <Contract>) await _repoWrapper.Contract.FindAllAsyncWithCondition(c => c.StudentId == student.StudentId && c.Status == ContractStatus.Active); if (contracts == null || !contracts.Any()) { throw new HttpStatusCodeException(HttpStatusCode.NotFound, "RenewContractService: Student doesn't have any active contract'"); } var renewContract = SendRenewContractRequestRequest.EntityFromRequest(request, contracts[0]); renewContract = await _repoWrapper.RenewContract.CreateAsync(renewContract); return(SendRenewContractRequestResponse.ResponseFromEntity(renewContract)); }
/// <summary> /// Check if student have staying for too long in dormitory /// </summary> /// <param name="student"></param> /// <returns></returns> private async Task <bool> CheckMaxYearForStayingForRenewContract(Student student) { //Get max year for students to be staying var maxYearForStaying = await _paramService.FindById(GlobalParams.ParamMaxYearForStaying); //Get student's startdate, beginning at September var startDate = new DateTime(student.StartedSchoolYear, 9, 1); // student's startdate = maxYearForStaying if (maxYearForStaying.Value != null) { var maxYear = startDate.AddYears(maxYearForStaying.Value.Value); // Get Now Time var now = DateTime.Now.AddHours(GlobalParams.TimeZone); return(now > maxYear); } return(false); }
public async Task <ActionResult <Param> > FindById(int id) { return(await _paramService.FindById(id)); }