Beispiel #1
0
 public HttpResponseMessage addForecast(dynamic pForecast)
 {
     try
     {
         using (PRINCE_STGEntities dbCtx = new PRINCE_STGEntities())
         {
             STG_FORECAST forecast = new STG_FORECAST();
             forecast.FORECAST_DATE              = pForecast.FORECAST_DATE;
             forecast.GEO_LEVEL1_CODE            = "99999";
             forecast.GEO_LEVEL2_CODE            = "99999";
             forecast.GEO_LEVEL3_CODE            = "99999";
             forecast.STORE_CODE                 = pForecast.STORE_CODE;
             forecast.PROD_LEVEL1_CODE           = pForecast.PROD_LEVEL1_CODE;
             forecast.PROD_LEVEL2_CODE           = pForecast.PROD_LEVEL2_CODE;
             forecast.PROD_LEVEL3_CODE           = "99999";
             forecast.PROD_LEVEL4_CODE           = "99999";
             forecast.PROD_LEVEL5_CODE           = "99999";
             forecast.PRODUCT_CODE               = "99999";
             forecast.FORECAST_SALE_QTY          = 99999;
             forecast.FORECAST_SALE_VAL_AT_PRICE = pForecast.FORECAST_SALE_VAL_AT_PRICE;
             forecast.FORECAST_SALE_VAL_AT_COST  = 99999;
             forecast.ARC_DATE = DateTime.Now;
             dbCtx.STG_FORECAST.Add(forecast);
             dbCtx.SaveChanges();
             return(Request.CreateResponse(HttpStatusCode.Created, "Forecast successfully created."));
         }
     }
     catch (Exception ex)
     {
         Request.CreateErrorResponse(HttpStatusCode.BadRequest, ex);
     }
     return(Request.CreateResponse(HttpStatusCode.OK));
 }
Beispiel #2
0
 public HttpResponseMessage updateForecast(dynamic pForecast)
 {
     try
     {
         using (PRINCE_STGEntities enBi = new PRINCE_STGEntities())
         {
             using (var dbCtxTran = enBi.Database.BeginTransaction())
             {
                 //DateTime merchdate = sStoreMerch.merch_DATE;
                 int id = pForecast.ID;
                 //string storecode = sStoreMerch.STORE_CODE;
                 STG_FORECAST forecast = enBi.STG_FORECAST.Find(id);
                 if (forecast != null)
                 {
                     forecast.ID                         = pForecast.ID;
                     forecast.FORECAST_DATE              = pForecast.FORECAST_DATE;
                     forecast.GEO_LEVEL1_CODE            = pForecast.GEO_LEVEL1_CODE;
                     forecast.GEO_LEVEL2_CODE            = pForecast.GEO_LEVEL2_CODE;
                     forecast.GEO_LEVEL3_CODE            = pForecast.GEO_LEVEL3_CODE;
                     forecast.STORE_CODE                 = pForecast.STORE_CODE;
                     forecast.PROD_LEVEL1_CODE           = pForecast.PROD_LEVEL1_CODE;
                     forecast.PROD_LEVEL2_CODE           = pForecast.PROD_LEVEL2_CODE;
                     forecast.PROD_LEVEL3_CODE           = pForecast.PROD_LEVEL3_CODE;
                     forecast.PROD_LEVEL4_CODE           = pForecast.PROD_LEVEL4_CODE;
                     forecast.PROD_LEVEL5_CODE           = pForecast.PROD_LEVEL5_CODE;
                     forecast.PRODUCT_CODE               = pForecast.PRODUCT_CODE;
                     forecast.FORECAST_SALE_QTY          = pForecast.FORECAST_SALE_QTY;
                     forecast.FORECAST_SALE_VAL_AT_PRICE = pForecast.FORECAST_SALE_VAL_AT_PRICE;
                     forecast.FORECAST_SALE_VAL_AT_COST  = pForecast.FORECAST_SALE_VAL_AT_COST;
                     forecast.ARC_DATE                   = pForecast.ARC_DATE;
                     enBi.Entry(forecast).State          = System.Data.Entity.EntityState.Modified;
                     enBi.SaveChanges();
                     dbCtxTran.Commit();
                     return(Request.CreateResponse(HttpStatusCode.OK, "Forecast successfully Updated."));
                 }
             }
         }
     }
     catch (DbEntityValidationException ex)
     {
         ExceptionEntity exDesc = new ExceptionEntity(ex);
         throw new ApiException()
               {
                   HttpStatus = HttpStatusCode.BadRequest, ErrorCode = (int)HttpStatusCode.BadRequest, ErrorDescription = exDesc.GetDescException()
               };
     }
     catch (Exception ex)
     {
         ExceptionDescription exDesc = new ExceptionDescription(ex);
         throw new ApiException()
               {
                   HttpStatus = HttpStatusCode.BadRequest, ErrorCode = (int)HttpStatusCode.BadRequest, ErrorDescription = exDesc.GetDescException()
               };
     }
     return(Request.CreateResponse(HttpStatusCode.OK, "Forecast successfully Updated."));
 }