Exemplo n.º 1
0
        public ActionResult Invoices_save()
        {
            var parameters = AjaxModel.GetAjaxParameters(HttpContext);
            var mng        = new GurevskiyRepository();
            var res        = false;
            int savedID    = 0;

            try
            {
                var fields = (parameters["fields"] as ArrayList).ToArray().ToList().Select(x => x as Dictionary <string, object>).ToList();

                var id        = RDL.Convert.StrToInt(AjaxModel.GetValueFromSaveField("id", fields), 0);
                var created   = RDL.Convert.StrToDateTime(AjaxModel.GetValueFromSaveField("date", fields), DateTime.Now);
                var number    = AjaxModel.GetValueFromSaveField("number", fields);
                var statusID  = RDL.Convert.StrToInt(AjaxModel.GetValueFromSaveField("statusName", fields), 0);
                var partnerID = RDL.Convert.StrToInt(AjaxModel.GetValueFromSaveField("partnerName", fields), 0);
                var comment   = AjaxModel.GetValueFromSaveField("comment", fields);

                var item = new gurevskiy_invoices {
                    id = id, statusID = statusID, partnerID = partnerID, date = created, number = number, comment = comment
                };
                res     = mng.SaveInvoice(item);
                savedID = item.id;
            }
            catch
            {
                res = false;
            }
            return(Json(new
            {
                result = res,
                savedID = savedID,
                msg = ""
            }, JsonRequestBehavior.AllowGet));
        }
Exemplo n.º 2
0
        public bool SaveInvoice(gurevskiy_invoices item)
        {
            bool res = false;

            if (item.id == 0)
            {
                db.gurevskiy_invoices.Add(item);
                res = Save();
            }
            else
            {
                db.Entry(item).State = EntityState.Modified;
                res = Save();
            }

            return(res);
        }