public ActionResult Edit([Bind(Include = "Request, GrantType, Description, Amount, Notes, EventDate, IsFromOtherBranch")] GrantRequest grantRequest)
        {
            Db db = new Db(DbServices.ConnectionString);

            if (ModelState.IsValid)
            {
                try
                {
                    GrantRequestServices.Update(CurrentUser.Id, grantRequest, db);
                    TempData["Success"] = ResourceServices.GetString(Cf.Data.Resources.ResourceBase.Culture, "UI", "UpdateConfirmed");
                    return(RedirectToAction("Index"));
                }
                catch (CfException cfex)
                {
                    TempData["Failure"] = cfex.ErrorDefinition.LocalizedMessage;
                }
                catch (Exception ex)
                {
                    TempData["Failure"] = ex.Message;
                }
            }

            ViewBag.GrantTypeList = new SelectList(GrantTypeServices.List(db), "Id", "Name", grantRequest.GrantType);
            ViewBag.RequestList   = new SelectList(RequestServices.List(db), "Product", "Attachment", grantRequest.Request);
            return(View(grantRequest));
        }
示例#2
0
        public ActionResult Edit(GrantRequestViewModel model)
        {
            int productId = model.RequestProduct.Id;

            try
            {
                Db db = new Db(DbServices.ConnectionString);

                if (!(db.Connection.State == ConnectionState.Open))
                {
                    db.Connection.Open();
                }
                db.Transaction = db.Connection.BeginTransaction();

                if (ModelState.IsValid)
                {
                    try
                    {
                        // 1- Update Prouct
                        ProductServices.Update(CurrentUser.Id, model.RequestProduct, db);

                        //2- Update Request
                        RequestServices.Update(CurrentUser.Id, model.Request, db);

                        //3- Update GrantRequest
                        GrantRequestServices.Update(CurrentUser.Id, model.GrantRequest, db);

                        TempData["Success"] = ResourceServices.GetString(Cf.Data.Resources.ResourceBase.Culture, "UI", "UpdateConfirmed");
                    }
                    catch (CfException cfex)
                    {
                        TempData["Failure"] = cfex.ErrorDefinition.LocalizedMessage;
                    }
                    catch (Exception ex)
                    {
                        TempData["Failure"] = ex.Message;
                    }
                }

                if (db.Transaction != null)
                {
                    db.Transaction.Commit();
                }
                if (productId == 0)
                {
                    return(RedirectToAction("Index"));
                }
                return(RedirectToAction("Details", new { id = productId }));
            }
            catch
            {
                return(View());
            }
        }