public async Task <IActionResult> CreateSingleTenderJustification([FromForm] SingleTenderJustificationFormModel model) { var userId = GetUserId(); var endPointId = await GetEndPointId(); if (ModelState.IsValid) { var singleTenderJustification = new TblSingleTenderJustification { Address = model.Address, ContactName = model.ContactName, Email = model.Email, TelephoneNumber = model.TelephoneNumber, ProjectId = model.ProjectId, ProposedContract = model.ProposedContract, ProposedContractValue = model.ProposedContractValue, ProposedContractor = model.ProposedContractor, Justification = model.Justification, AdditionalInfo = UploadFile(model.AdditionalInfo), CreatedDate = DateTime.Now, }; await _singleTenderJustificationRepository.CreateAsync(singleTenderJustification); var tblStaff = await _staffRepository.FirstOrDefaultAsync(x => x.AspnetUserId == userId); // write logic to create TblAuthList object var newAudit = new TblAuthList { Title = "Single Tender Justification", Url = "/api/v1/justificationofaward/createsingletenderjustification", CreatedDate = DateTime.Now, Status = 0, StaffId = tblStaff.StaffId, BatchId = Guid.NewGuid().ToString() }; await _auditRepository.CreateAsync(newAudit); // login for email notification var emailAddress = await _emailAddressRepository.SendEmailAddress(endPointId, 1); await _auditRepository.SaveChangesAsync(); return(Ok( new { message = "Single Tender Justification created successfully", EmailAddress = emailAddress })); } return(BadRequest(new { Errors = new[] { "Please input correct values" } })); }
public async Task <IActionResult> UpdateSingleTenderJustfication([FromForm] SingleTenderJustificationFormModel model, [FromQuery] int singleTenderJustficationId) { var userId = GetUserId(); var endPointId = await GetEndPointId(); if (ModelState.IsValid) { var singleTenderJustification = await _singleTenderJustificationRepository.GetByIdAsync(singleTenderJustficationId); if (singleTenderJustification == null) { return(NotFound(new { message = "Single Tender Justification does not exist" })); } // assign updated fields singleTenderJustification.Address = model.Address; singleTenderJustification.ContactName = model.ContactName; singleTenderJustification.Email = model.Email; singleTenderJustification.TelephoneNumber = model.TelephoneNumber; singleTenderJustification.ProjectId = model.ProjectId; singleTenderJustification.ProposedContract = model.ProposedContract; singleTenderJustification.ProposedContractValue = model.ProposedContractValue; singleTenderJustification.ProposedContractor = model.ProposedContractor; singleTenderJustification.Justification = model.Justification; singleTenderJustification.AdditionalInfo = UploadFile(model.AdditionalInfo); _singleTenderJustificationRepository.Update(singleTenderJustification); var tblStaff = await _staffRepository.FirstOrDefaultAsync(x => x.AspnetUserId == userId); // write logic to create TblAuthList object var newAudit = new TblAuthList { Title = "Single Tender Justfication", Url = "/api/v1/justficationofaward/updatesingletenderjustification", CreatedDate = DateTime.Now, Status = 0, StaffId = tblStaff.StaffId, BatchId = Guid.NewGuid().ToString() }; await _auditRepository.CreateAsync(newAudit); // login for email notification var emailAddress = await _emailAddressRepository.SendEmailAddress(endPointId, 1); await _auditRepository.SaveChangesAsync(); return(Ok( new { message = "Single Tender Justification updated successfully", EmailAddress = emailAddress })); } return(BadRequest(new { Errors = new[] { "Please input correct values" } })); }