コード例 #1
0
        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);
        }
コード例 #2
0
        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());
        }
コード例 #3
0
        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);
        }