public async Task <QuotationRequested> UpdateRequest(QuotationRequested qr, int id, string userId) { try { var dbQr = await Db.QuotationRequesteds.FindAsync(id); var user = await UserManager.FindByIdAsync(userId); var executive = await Db.Executives.FirstOrDefaultAsync(e => e.Email == user.Email); if (dbQr == null && dbQr.CompanyId != qr.CompanyId && qr.CompanyId != executive.CompanyId) { return(null); } dbQr.Description = qr.Description; dbQr.SkillIds = qr.SkillIds; dbQr.Budget = qr.Budget; dbQr.ProjectEnd = dbQr.ProjectEnd; dbQr.ProjectStart = dbQr.ProjectStart; Db.Update(dbQr); await Db.SaveChangesAsync(); return(dbQr); } catch (Exception ex) { return(null); } }
public async Task <IActionResult> Put(int id, [FromBody] QuotationRequested qr) { var claimsIdentity = this.User.Identity as ClaimsIdentity; var userId = claimsIdentity.FindFirst(ClaimTypes.Name)?.Value; return(Ok(await QS.UpdateRequest(qr, id, userId))); }
public async Task <IActionResult> CreateQuotationRequest([FromBody] QuotationRequested qr) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var claimsIdentity = this.User.Identity as ClaimsIdentity; var userId = claimsIdentity.FindFirst(ClaimTypes.Name)?.Value; var data = await QS.CreateRequest(qr, userId); if (data != null) { return(Created($"api/quotation/{data.Id}", data)); } return(BadRequest()); }
public async Task <QuotationRequested> CreateRequest(QuotationRequested qr, string userId) { try { var user = await UserManager.FindByIdAsync(userId); var executive = await Db.Executives.FirstOrDefaultAsync(e => e.Email == user.Email); if (executive == null) { return(null); } qr.CompanyId = executive.Id; await Db.AddAsync(qr); await Db.SaveChangesAsync(); return(qr); } catch (Exception ex) { return(null); } }