Beispiel #1
0
        public IHttpActionResult PutSalesTrend(int id, int tid, [FromBody] TrendApiModel model, [FromUri] SalesViewApiParameterModel param)
        {
            if (tid == 0 || model == null || model.Id == 0)
            {
                WriteAppLog("PUT SalesViews/" + id.ToString() + "/Trends/" + tid.ToString(), "パラメーターエラー");
                return(BadRequest());
            }

            SalesTrendModel work = dbContext.SalesTrendModels.Where(st => st.Id == tid).SingleOrDefault();

            if (work == null)
            {
                WriteAppLog("PUT SalesViews/" + id.ToString() + "/Trends/" + tid.ToString(), "データが存在しない");
                return(NotFound());
            }

            work.TargetDate  = model.Detail_date;
            work.Sales       = model.Quantity;
            work.Comments    = model.Comments;
            work.UserModelId = model.User_id;
            dbContext.SaveChanges();
            model.User_name = dbContext.UserModels.Where(um => um.Id == model.User_id).Select(um => um.Name).SingleOrDefault();

            WriteAppLog("PUT SalesViews/" + id.ToString() + "/Trends/" + tid.ToString(), "処理成功");
            return(Ok(model));
        }
Beispiel #2
0
        public IHttpActionResult PostSalesTrend(int id, [FromBody] TrendApiModel model, [FromUri] SalesViewApiParameterModel param)
        {
            if (model == null || model.Id != 0)
            {
                WriteAppLog("POST SalesViews/" + id.ToString() + "/Trends", "パラメーターエラー");
                return(BadRequest());
            }

            SalesTrendModel addmodel = new SalesTrendModel();

            addmodel.ProductModelId = model.Product_id;
            addmodel.TargetDate     = model.Detail_date.Date;
            addmodel.Sales          = model.Quantity;
            addmodel.Comments       = model.Comments;
            addmodel.UserModelId    = model.User_id;
            addmodel.Deleted        = false;

            dbContext.Database.ExecuteSqlCommand(ContextResources.IncrementResetSalesTrend);
            dbContext.SalesTrendModels.Add(addmodel);
            dbContext.SaveChanges();
            dbContext.Database.ExecuteSqlCommand(ContextResources.IncrementResetSalesTrend);

            model.Id        = addmodel.Id;
            model.User_name = dbContext.UserModels.Where(um => um.Id == addmodel.UserModelId).Select(um => um.Name).SingleOrDefault();
            if (model.Id == 0)
            {
                WriteAppLog("POST SalesViews/" + id.ToString() + "/Trends", "登録処理に失敗");
                return(BadRequest());
            }

            WriteAppLog("POST SalesViews/" + id.ToString() + "/Trends", "処理成功");
            return(Ok(model));
        }