public async Task <IActionResult> AddSemester(SemesterDtoForAdd model) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (await _repo.SemesterExists(model.Name)) { return(BadRequest(new { message = "This semester is already exist" })); } _response = await _repo.AddSemester(model); return(Ok(_response)); }
public async Task <ServiceResponse <object> > AddSemester(SemesterDtoForAdd model) { DateTime StartDate = DateTime.ParseExact(model.StartDate, "MM/dd/yyyy", null); DateTime EndDate = DateTime.ParseExact(model.EndDate, "MM/dd/yyyy", null); DateTime DueDate = DateTime.ParseExact(model.DueDate, "MM/dd/yyyy", null); var ToAdd = new Semester { Name = model.Name, FeeAmount = Convert.ToDouble(model.FeeAmount), StartDate = StartDate, EndDate = EndDate, DueDate = DueDate, LateFeePlentyAmount = Convert.ToInt32(model.LateFeePlentyAmount), LateFeeValidityInDays = Convert.ToInt32(model.LateFeeValidityInDays), Posted = false, Active = true, CreatedDateTime = DateTime.UtcNow, CreatedById = _LoggedIn_UserID, SchoolBranchId = _LoggedIn_BranchID, }; await _context.Semesters.AddAsync(ToAdd); await _context.SaveChangesAsync(); var ToAdd2 = new SemesterFeeTransaction { SemesterId = ToAdd.Id, Amount = Convert.ToDouble(model.FeeAmount), UpdatedDateTime = DateTime.UtcNow, UpdatedById = _LoggedIn_UserID, SchoolBranchId = _LoggedIn_BranchID, }; await _context.SemesterFeeTransactions.AddAsync(ToAdd2); await _context.SaveChangesAsync(); _serviceResponse.Success = true; _serviceResponse.Message = CustomMessage.Added; return(_serviceResponse); }