Exemplo n.º 1
0
        public ActionResult Create([Bind(Include = "ID,AccountName,GlCategoryID,BranchID")] GlAccount glAccount)
        {
            ViewBag.BranchID     = new SelectList(db.Branches, "ID", "Name", glAccount.BranchID);
            ViewBag.GlCategoryID = new SelectList(db.GlCategories, "ID", "Name", glAccount.GlCategoryID);

            if (ModelState.IsValid)
            {
                try
                {
                    if (!glActLogic.IsUniqueName(glAccount.AccountName))
                    {
                        AddError("Account name must be unique");
                        return(View(glAccount));
                    }

                    GlCategory glCategory = db.GlCategories.Find(glAccount.GlCategoryID);

                    glAccount.CodeNumber     = glActLogic.GenerateGLAccountNumber(glCategory.MainCategory);
                    glAccount.AccountBalance = 0;
                    db.GlAccounts.Add(glAccount);
                    db.SaveChanges();
                    return(RedirectToAction("Index"));
                }
                catch (Exception ex)
                {
                    AddError(ex.ToString());
                    return(View(glAccount));
                }
            }
            AddError("Please enter valid data");
            return(View(glAccount));
        }
Exemplo n.º 2
0
        public ActionResult Create(AddGlActViewModel model)
        {
            ViewBag.GlCategoryId = new SelectList(glCatRepo.GetAll(), "ID", "Name", model.GlCategoryId);
            ViewBag.BranchId     = new SelectList(branchRepo.GetAll(), "ID", "Name", model.BranchId);

            if (ModelState.IsValid)
            {
                try
                {
                    var            category     = glCatRepo.GetById(model.GlCategoryId);
                    var            branch       = branchRepo.GetById(model.BranchId);
                    MainGlCategory mainCategory = (MainGlCategory)((int)category.MainCategory);

                    //if is unique account name
                    if (!gllogic.IsUniqueName(model.AccountName))
                    {
                        ViewBag.Msg = "Account name must be unique";
                        return(View(model));
                    }

                    GlAccount glAccount = new GlAccount()
                    {
                        AccountName = model.AccountName, GlCategory = category, Branch = branch, CodeNumber = gllogic.GenerateGLAccountNumber(mainCategory)
                    };
                    glactRepo.Insert(glAccount);
                    //ViewBag.Msg = "successfully added account";

                    return(RedirectToAction("Create", new { message = "successfully added account" }));
                }
                catch (Exception ex)
                {
                    //ErrorLogger.Log("Message= " + ex.Message + "\nInner Exception= " + ex.InnerException + "\n");
                    return(PartialView("Error"));
                }
            }

            ViewBag.Msg = "Please enter correct data";
            return(View(model));
        }