public async Task <ServiceResponse <object> > UpdateSemester(SemesterDtoForEdit model) { var ObjToUpdate = _context.Semesters.FirstOrDefault(s => s.Id.Equals(model.Id)); if (ObjToUpdate != null) { 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); ObjToUpdate.Name = model.Name; ObjToUpdate.FeeAmount = Convert.ToDouble(model.FeeAmount); ObjToUpdate.LateFeePlentyAmount = Convert.ToInt32(model.LateFeePlentyAmount); ObjToUpdate.StartDate = StartDate; ObjToUpdate.EndDate = EndDate; ObjToUpdate.DueDate = DueDate; ObjToUpdate.LateFeePlentyAmount = Convert.ToInt32(model.LateFeePlentyAmount); ObjToUpdate.LateFeeValidityInDays = Convert.ToInt32(model.LateFeeValidityInDays); _context.Semesters.Update(ObjToUpdate); await _context.SaveChangesAsync(); } if (ObjToUpdate.FeeAmount.ToString() != model.FeeAmount) { var ToAdd = new SemesterFeeTransaction { SemesterId = ObjToUpdate.Id, Amount = Convert.ToDouble(model.FeeAmount), UpdatedDateTime = DateTime.UtcNow, UpdatedById = _LoggedIn_UserID, SchoolBranchId = _LoggedIn_BranchID, }; await _context.SemesterFeeTransactions.AddAsync(ToAdd); await _context.SaveChangesAsync(); } _serviceResponse.Message = CustomMessage.Updated; _serviceResponse.Success = true; return(_serviceResponse); }
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); }