public async Task <JsonResult> PutService(int id, [FromBody] SendServices service) { var ser = await _context.Services.FindAsync(id); _context.Entry(ser).State = EntityState.Modified; ser.name = service.name; ser.minutes = service.minutes; ser.price = service.price; ser.descride = service.descride; try { await _context.SaveChangesAsync(); return(new JsonResult(_responce.Return_Responce(System.Net.HttpStatusCode.OK, service, null))); } catch (DbUpdateConcurrencyException) { if (!ServiceExists(id)) { return(new JsonResult(_responce.Return_Responce(System.Net.HttpStatusCode.NotFound, service, null))); } else { throw; } } return(new JsonResult(_responce.Return_Responce(System.Net.HttpStatusCode.NoContent, service, null))); }
public async Task <JsonResult> PostService([FromBody] SendServices service, [FromHeader] string Authorization) { try { string token = Authorization.Split(' ')[1]; var user = (from bb in _context.Auths join aa in _context.Tokens on bb.id equals aa.user_id join cc in _context.EmployeeOwners on bb.id equals cc.id_user where aa.access == token select cc).FirstOrDefault(); var categ = await _context.Categories.Where(x => x.name == service.category).FirstOrDefaultAsync(); ServiceHelpers help = new ServiceHelpers(); StaffService serv = help.LoadService(service, categ.id); serv.account_id = user.id; await _context.Services.AddAsync(serv); await _context.SaveChangesAsync(); return(new JsonResult(_responce.Return_Responce(System.Net.HttpStatusCode.Created, serv, null))); } catch (Exception ex) { return(new JsonResult(_responce.Return_Responce(System.Net.HttpStatusCode.BadRequest, null, ex.Message))); } }
public StaffService LoadService(SendServices send, int id_category) { StaffService st = new StaffService(); st.category = id_category; st.descride = send.descride; st.price = send.price; st.minutes = send.minutes; st.name = send.name; return(st); }