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

            if (ModelState.IsValid)
            {
                try
                {
                    GrantRequestServices.Insert(CurrentUser.Id, grantRequest, db);
                    TempData["Success"] = ResourceServices.GetString(Cf.Data.Resources.ResourceBase.Culture, "UI", "InsertConfirmed");
                    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");
            ViewBag.RequestList   = new SelectList(RequestServices.List(db), "Product", "Attachment");
            return(View(grantRequest));
        }
Exemplo n.º 2
0
        public ActionResult Create(GrantRequestViewModel model)
        {
            int productId = 0;

            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- Add Prouct
                        // set the Amount of the Produt the same as Request
                        model.RequestProduct.Amount      = model.Request.Amount;
                        model.RequestProduct.ProductType = 0;

                        Product p = ProductServices.Insert(CurrentUser.Id, model.RequestProduct, db);
                        productId = p.Id;

                        //2-Add Request
                        model.Request.Product       = p.Id;
                        model.Request.RequestStatus = (int)RequestStatusEnum.New;
                        model.Request.Cost          = 5;
                        Request r = RequestServices.Insert(CurrentUser.Id, model.Request, db);

                        //3-Add GrantRequest
                        model.GrantRequest.Request = p.Id;
                        model.GrantRequest.Amount  = model.Request.Amount;

                        GrantRequestServices.Insert(CurrentUser.Id, model.GrantRequest, db);

                        TempData["Success"] = ResourceServices.GetString(Cf.Data.Resources.ResourceBase.Culture, "UI", "InsertConfirmed");
                    }
                    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());
            }
        }