コード例 #1
0
        public JsonResult SaveChanges(int id, string newValue, PriceListFieldName priceListFieldName)
        {
            var jsonSuccessResult = new JsonSuccessResult();

            try
            {
                string oldValue = String.Empty;

                // Update Row
                PriceListProducts.SaveChanges(id, newValue, priceListFieldName, out oldValue);

                // Insert Log
                #region Log

                PriceListLog log = new PriceListLog
                {
                    OldValue           = oldValue,
                    NewValue           = newValue,
                    PriceListFieldName = priceListFieldName,
                    PriceListProductID = id,
                    LastUpdate         = DateTime.Now
                };

                PriceListLogs.Inset(log);

                #endregion Log

                jsonSuccessResult.Success = true;
            }
            catch (Exception ex)
            {
                jsonSuccessResult.Errors  = new string[] { ex.Message };
                jsonSuccessResult.Success = false;
            }

            return(new JsonResult()
            {
                Data = jsonSuccessResult
            });
        }
コード例 #2
0
        public static void SaveChanges(int id, string value, PriceListFieldName priceListFieldName, out string oldValue)
        {
            using (var db = OnlineStoreDbContext.Entity)
            {
                oldValue = String.Empty;

                var orgPriceListProduct = db.PriceListProducts.Where(item => item.ID == id).Single();

                switch (priceListFieldName)
                {
                case PriceListFieldName.Title:
                    oldValue = orgPriceListProduct.Title;
                    orgPriceListProduct.Title = value;
                    break;

                case PriceListFieldName.SubTitle:
                    oldValue = orgPriceListProduct.SubTitle;
                    orgPriceListProduct.SubTitle = value;
                    break;

                case PriceListFieldName.Price:
                    oldValue = orgPriceListProduct.Price.ToString();
                    orgPriceListProduct.Price = Int32.Parse(value);
                    break;

                case PriceListFieldName.IsAvailable:
                    oldValue = orgPriceListProduct.IsAvailable.ToString();
                    orgPriceListProduct.IsAvailable = Boolean.Parse(value);
                    break;

                default:
                    break;
                }

                orgPriceListProduct.LastUpdate = DateTime.Now;

                db.SaveChanges();
            }
        }