Ejemplo n.º 1
0
        // GET: /GlAccount/Create
        public ActionResult Create(string message)
        {
            ViewBag.Msg          = message;
            ViewBag.GlCategoryId = new SelectList(glCatRepo.GetAll(), "ID", "Name");
            ViewBag.BranchId     = new SelectList(branchRepo.GetAll(), "ID", "Name");
            var model = new AddGlActViewModel();

            return(View(model));
        }
Ejemplo 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));
        }