public async Task <ActionResult <AddressDTO> > AddNewAddress([FromBody] AddressDTO newAddress) { var address = _addresssMapper.Map <Address>(newAddress); await _context.Addresses.AddAsync(address); await _context.SaveChangesAsync(); return(CreatedAtAction( nameof(AddNewAddress), new { newAddress })); }
public async Task <ActionResult <JobDTO> > AddNewJob([FromBody] JobDTO newJob) { if (await _context.Jobs.AnyAsync(x => x.JobNumber.Equals(newJob.JobNumber))) { _logger.LogWarning("An existing Job was sent to AddNewJob."); return(BadRequest("Error: A Job already exists with that Job Number.")); } if (newJob.DeviceType != "LS Vial" || newJob.DeviceType != "CRM") { _logger.LogWarning("Incorrect DeviceType input. Only 'LS Vial' and 'CRM' is acceptable."); return(BadRequest("Error: Device Type must be 'LS Vial' or 'CRM'.")); } var user = await _context.Users.FindAsync(User.Identity.Name); var job = _jobsMapper.Map <Job>(newJob); job.LastUpdatedBy = user.UserName + DateTime.UtcNow.ToShortDateString(); await _context.Jobs.AddAsync(job); await _context.SaveChangesAsync(); return(CreatedAtAction( nameof(AddNewJob), new { jn = job.JobNumber, user.UserName, dateCreated = DateTime.UtcNow.ToShortDateString() })); }
public async Task <ActionResult <ContinuousRadonMonitorDTO> > AddNewCRM([FromBody] ContinuousRadonMonitorDTO newCRM) { if (await _context.ContinuousRadonMonitors.AnyAsync(c => c.SerialNumber == newCRM.SerialNumber)) { return(BadRequest("Error: A CRM with that Serial Number already exists.")); } if (await _context.ContinuousRadonMonitors.AnyAsync(c => c.MonitorNumber == newCRM.MonitorNumber)) { return(BadRequest("Error: A CRM with that Monitor Number already exists.")); } var user = await _context.Users.FindAsync(User.Identity.Name); var cRM = _cRMMapper.Map <ContinuousRadonMonitor>(newCRM); cRM.TestFinish = cRM.TestStart.AddDays(2); cRM.LastUpdatedBy = user.UserName + DateTime.UtcNow.ToShortDateString(); cRM.MaintenanceLog = new List <CRMMaintenanceLogEntry> { }; await _context.ContinuousRadonMonitors.AddAsync(cRM); await _context.SaveChangesAsync(); return(CreatedAtAction( nameof(AddNewCRM), new { cRM.SerialNumber, cRM.MonitorNumber, user.UserName, dateCreated = DateTime.UtcNow.ToShortDateString() })); }
public async Task <IActionResult> AddNewLSVial([FromBody] LSVialDTO newLSVial) { if (await _context.LSVials.AnyAsync(x => x.SerialNumber.Equals(newLSVial.SerialNumber))) { return(BadRequest("Error: A LS Vial already exists with that Serial Number.")); } var user = await _context.Users.FindAsync(User.Identity.Name); var lSVial = new LSVial() { SerialNumber = newLSVial.SerialNumber, Status = newLSVial.Status, TestStart = newLSVial.TestStart, TestFinish = newLSVial.TestStart.AddDays(2), JobHistory = new List <Job> { }, LastUpdatedBy = user.UserName + DateTime.UtcNow.ToShortDateString() }; Job job; bool jobExists = await _context.Jobs.AnyAsync(x => x.JobNumber.Equals(newLSVial.JobNumber)); if (jobExists) { job = await _context.Jobs.FirstOrDefaultAsync(y => y.JobNumber == newLSVial.JobNumber); } else { job = new Job() { JobNumber = newLSVial.JobNumber }; await _context.Jobs.AddAsync(job); } lSVial.JobHistory.Add(job); await _context.LSVials.AddAsync(lSVial); await _context.SaveChangesAsync(); return(CreatedAtAction( nameof(GetLSVialBySerialNumber), new { sn = lSVial.SerialNumber, jobNum = job.JobNumber, user, dateCreated = DateTime.UtcNow })); }