public async Task <IActionResult> Create([FromBody] BillCreateRequest req) { var ownerId = this.User.FindFirstValue(ClaimTypes.NameIdentifier); var bill = await _billService.Create(ownerId, req); if (bill == null) { return(BadRequest(new { message = "Network error. Bill could not be created." })); } return(Created(string.Empty, bill)); }
public async Task <BillResponse> Create(string ownerId, BillCreateRequest req) { var bill = new BillModel() { id = Guid.NewGuid(), created_ts = DateTime.Now, updated_ts = DateTime.Now, owner_id = new Guid(ownerId), vendor = req.vendor, bill_date = Convert.ToDateTime(req.bill_date).Date, due_date = Convert.ToDateTime(req.due_date).Date, amount_due = req.amount_due, categories = string.Join(',', req.categories), payment_status = (int)((PaymentStatusEnum)Enum.Parse(typeof(PaymentStatusEnum), req.payment_status)) }; _context.Bill.Add(bill); await _context.SaveChangesAsync(); return(_mapper.Map <BillResponse>(bill)); }