public async Task <IActionResult> PutVoucherCustomer([FromRoute] int id, [FromBody] VoucherCustomer voucherCustomer) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != voucherCustomer.Voucher_Customer_Id) { return(BadRequest()); } _context.Entry(voucherCustomer).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!VoucherCustomerExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <IActionResult> PostVoucherCustomer([FromBody] VoucherCustomer voucherCustomer) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } _context.VoucherCustomer.Add(voucherCustomer); await _context.SaveChangesAsync(); return(CreatedAtAction("GetVoucherCustomer", new { id = voucherCustomer.Voucher_Customer_Id }, voucherCustomer)); }
public async Task <JsonResult> AssignCustomer(int customer_id, int voucher_id, DateTime start) { var el = new VoucherCustomer { Added = start, Voucher_Id = voucher_id, Customer_Id = customer_id, IsActive = true }; var voucher = await _apiContext.GetRequest("Vouchers/" + voucher_id); var vc = JsonConvert.DeserializeObject <Voucher>(voucher.Value.ToString()); if (vc != null) { el.Voucher_Customer_Suspend_Number = vc.Voucher_Max_Suspend_Times; // ustawiamy licznik na możliwą liczbę zamrożeń if (vc.Voucher_Startdate != null) { if (start < vc.Voucher_Startdate) { Response.StatusCode = 404; return(new JsonResult("Okres rozpoczęcia karnetu przypada przed zadeklarowaną datą!")); } } if (vc.Voucher_Type_Id == 1) { // open if (vc.VoucherDaysNumber.HasValue && vc.VoucherDaysNumber > 0) { var diff = start.AddDays(vc.VoucherDaysNumber.Value); if (vc.Voucher_Enddate != null) { if (diff > vc.Voucher_Enddate) { Response.StatusCode = 404; return(new JsonResult("Okres zakończenia karnetu przypada po określonym limicie!")); } } el.VoucherEndDate = diff; el.FreeEntries = vc.Voucher_Entries_Number; } if (vc.Voucher_Entries_Number.HasValue && vc.Voucher_Entries_Number > 0) { el.FreeEntries = vc.Voucher_Entries_Number; } } else if (vc.Voucher_Type_Id == 2) { if (vc.VoucherDaysNumber.HasValue && vc.VoucherDaysNumber > 0) { var diff = start.AddDays(vc.VoucherDaysNumber.Value); if (vc.Voucher_Enddate != null) { if (diff > vc.Voucher_Enddate) { Response.StatusCode = 404; return(new JsonResult("Okres zakończenia karnetu przypada po określonym limicie!")); } } el.VoucherEndDate = diff; el.FreeEntries = vc.Voucher_Entries_Number; } // okresowy } else if (vc.Voucher_Type_Id == 3) { // ilościowy if (vc.Voucher_Entries_Number.HasValue) { el.FreeEntries = vc.Voucher_Entries_Number; } } var result = await _apiContext.PostRequest("VoucherCustomers", el); if (result.Value.ToString() == "400") { Response.StatusCode = 404; return(new JsonResult("Wystąpił błąd podczas przypisywanie vouchera. Zweryfikuj poprawność danych")); } return(result); } else { return(new JsonResult("Nie odnalazłem takiego karnetu w systemie.")); } }