Example #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));
        }
Example #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));
        }
Example #3
0
        public RepositoryResult <SalesTrendInterfaceModel> CreateSalesTrend(int productId, SalesTrendInterfaceModel createSalesTrend)
        {
            if (createSalesTrend == null || createSalesTrend.Id != 0)
            {
                return(new RepositoryResult <SalesTrendInterfaceModel>(HttpStatusCode.BadRequest));
            }

            using (DataContext dbContext = DataContext.Create())
            {
                var addmodel = new SalesTrendModel();
                addmodel.ProductModelId = createSalesTrend.Product_id;
                addmodel.TargetDate     = createSalesTrend.Detail_date.Date;
                addmodel.Sales          = createSalesTrend.Quantity;
                addmodel.Comments       = createSalesTrend.Comments;
                addmodel.UserModelId    = createSalesTrend.User_id;
                addmodel.Deleted        = false;

                dbContext.Database.ExecuteSqlCommand(ServiceResource.IncrementResetSalesTrend);
                dbContext.SalesTrendModels.Add(addmodel);
                if (dbContext.SaveChanges() == 0)
                {
                    return(new RepositoryResult <SalesTrendInterfaceModel>(HttpStatusCode.BadRequest));
                }
                dbContext.Database.ExecuteSqlCommand(ServiceResource.IncrementResetSalesTrend);

                var result = GetSalesTrandsByIdForInterface(productId, addmodel.Id);
                if (result.Code != HttpStatusCode.OK)
                {
                    return(new RepositoryResult <SalesTrendInterfaceModel>(HttpStatusCode.OK));
                }
                return(new RepositoryResult <SalesTrendInterfaceModel>(HttpStatusCode.OK, result.resultData));
            }
        }
Example #4
0
 public RepositoryResult <SalesTrendInterfaceModel> DeleteSalesTrend(int productId, int trendId)
 {
     using (DataContext dbContext = DataContext.Create())
     {
         SalesTrendModel work = dbContext.SalesTrendModels.Where(st => st.Id == trendId).Where(st => st.ProductModelId == productId).SingleOrDefault();
         if (work == null)
         {
             return(new RepositoryResult <SalesTrendInterfaceModel>(HttpStatusCode.NotFound));
         }
         work.Deleted = true;
         if (dbContext.SaveChanges() == 0)
         {
             return(new RepositoryResult <SalesTrendInterfaceModel>(HttpStatusCode.BadRequest));
         }
         return(new RepositoryResult <SalesTrendInterfaceModel>(HttpStatusCode.OK));
     }
 }
Example #5
0
        public IHttpActionResult DeleteSalesTrend(int id, int tid, [FromUri] SalesViewApiParameterModel param)
        {
            if (tid == 0)
            {
                WriteAppLog("DELETE SalesViews/" + id.ToString() + "/Trends/" + tid.ToString(), "パラメーターエラー");
                return(BadRequest());
            }

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

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

            work.Deleted = true;
            dbContext.SaveChanges();

            WriteAppLog("DELETE SalesViews/" + id.ToString() + "/Trends/" + tid.ToString(), "処理成功");

            return(Ok());
        }