Пример #1
0
        public ActionResult AddFuelprice(string EffectiveDate, double Price)
        {
            this.Internationalization();
            try
            {
                TugDataEntities db = new TugDataEntities();
                TugDataModel.Fuelprice price = new Fuelprice();
                price.EffectiveDate = EffectiveDate;
                price.Price = Price;
                price.Type = "";
                price.Unit = "";
                price.CreateDate = price.LastUpDate = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
                price.AddUserID = Session.GetDataFromSession<int>("userid");
                price = db.Fuelprice.Add(price);
                db.SaveChanges();

                    var ret = new { code = Resources.Common.SUCCESS_CODE, message = Resources.Common.SUCCESS_MESSAGE };
                    return Json(ret);
                }

            catch (Exception ex)
            {
                throw ex;
            }
        }
Пример #2
0
        public ActionResult AddEdit(string EffectiveDate, double Price)
        {
            this.Internationalization();

            #region Add

            if (Request.Form["oper"].Equals("add"))
            {
                try
                {
                    TugDataEntities db = new TugDataEntities();
                    {
                        TugDataModel.Fuelprice price = new Fuelprice();

                        price.EffectiveDate = EffectiveDate;
                        price.Price = Price;
                        price.Unit = "";
                        price.Type ="";
                        price.CreateDate = price.LastUpDate = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"); ;
                        price.AddUserID = Session.GetDataFromSession<int>("userid");
                        price = db.Fuelprice.Add(price);
                        db.SaveChanges();

                        var ret = new { code = Resources.Common.SUCCESS_CODE, message = Resources.Common.SUCCESS_MESSAGE };
                        return Json(ret);
                    }
                }
                catch (Exception)
                {
                    var ret = new { code = Resources.Common.EXCEPTION_CODE, message = Resources.Common.EXCEPTION_MESSAGE };
                    //Response.Write(@Resources.Common.EXCEPTION_MESSAGE);
                    return Json(ret);
                }
            }

            #endregion Add

            #region Edit

            if (Request.Form["oper"].Equals("edit"))
            {
                try
                {
                    TugDataEntities db = new TugDataEntities();
                    int idx = Util.toint(Request.Form["IDX"]);
                    Fuelprice price = db.Fuelprice.Where(u => u.IDX == idx).FirstOrDefault();

                    if (price == null)
                    {
                        return Json(new { code = Resources.Common.ERROR_CODE, message = Resources.Common.ERROR_MESSAGE });
                    }
                    else
                    {
                        price.EffectiveDate = EffectiveDate;
                        price.Price = Price;
                        price.Unit = "";
                        price.Type = "";
                        price.CreateDate = price.LastUpDate = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"); ;
                        price.AddUserID = Session.GetDataFromSession<int>("userid");
                        db.Entry(price).State = System.Data.Entity.EntityState.Modified;
                        db.SaveChanges();

                        return Json(new { code = Resources.Common.SUCCESS_CODE, message = Resources.Common.SUCCESS_MESSAGE });
                    }
                }
                catch (Exception exp)
                {
                    return Json(new { code = Resources.Common.EXCEPTION_CODE, message = Resources.Common.EXCEPTION_MESSAGE });
                }
            }

            #endregion Edit

            return Json(new { code = Resources.Common.ERROR_CODE, message = Resources.Common.ERROR_MESSAGE });
        }