public async Task <ActionResult <AdminPutResponse> > PutAdmin(AdminPutRequest request) { if (!(await checkToken(request.username, request.token))) { return(BadRequest()); } AdminPutResponse result = new AdminPutResponse(); using (var db = new NutrientContext()) { NutrientModel model = await db.nutrients.FindAsync(request.id); if (model == null) { return(NotFound()); } DateTime dt = DateTime.Now; model.approval = true; model.approvaled_at = dt; db.nutrients.Update(model); await db.SaveChangesAsync(); result.token = await updateToken(request.username); } return(result); }
public async Task <ActionResult> PostNutrient(NutrientPostRequest item) { using (var db = new NutrientContext()) { NutrientModel model = new NutrientModel(); DateTime dt = DateTime.Now; model.name = item.name; model.protein = item.protein; model.lipid = item.lipid; model.carbohydrate = item.carbohydrate; model.calorie = item.calorie; model.created_at = dt; model.updated_at = dt; db.nutrients.Add(model); await db.SaveChangesAsync(); } return(NoContent()); }
public async Task <ActionResult <AdminDeleteResponse> > DeleteAdmin(AdminDeleteRequest request) { if (!(await checkToken(request.username, request.token))) { return(BadRequest()); } AdminDeleteResponse result = new AdminDeleteResponse(); using (var db = new NutrientContext()) { NutrientModel model = await db.nutrients.FindAsync(request.id); if (model == null) { return(NotFound()); } db.nutrients.Remove(model); await db.SaveChangesAsync(); result.token = await updateToken(request.username); } return(result); }