// GET: /GlCategory/Create public ActionResult Create(string message) { ViewBag.Msg = message; GlCategory model = new GlCategory(); return(View(model)); }
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)); }
public ActionResult Create([Bind(Include = "ID,MainCategory,Name,Description")] GlCategory glcategory) { if (ModelState.IsValid) { try { //check for unique name if (!categLogic.IsUniqueName(glcategory.Name)) { ViewBag.Msg = "Please select another name"; return(View()); } glCatRepo.Insert(glcategory); return(RedirectToAction("Create", new { message = "Category created successfully" })); } catch (Exception ex) { //ErrorLogger.Log("Message= " + ex.Message + "\nInner Exception= " + ex.InnerException + "\n"); return(PartialView("Error")); } } ViewBag.Msg = "Please enter correct data"; return(View(glcategory)); }
public ActionResult Create([Bind(Include = "ID,Name,Description,MainCategory")] GlCategory glCategory) { if (ModelState.IsValid) { try { if (!glCatLogic.IsUniqueName(glCategory.Name)) { AddError("Please select another name"); return(View(glCategory)); } db.GlCategories.Add(glCategory); db.SaveChanges(); return(RedirectToAction("Index")); } catch (Exception ex) { AddError(ex.ToString()); return(View(glCategory)); } } AddError("Please enter valid data"); return(View(glCategory)); }
public ActionResult Save(GlCategory category) { if (ModelState.IsValid) { var categoryInDb = _context.Get(category.Id); if (category.Id == 0 && category.MainAccountCategory != 0) { _context.Save(category); TempData["Success"] = "Category Added Successfully"; return(RedirectToAction("Index")); } if (category.Id != 0) //update Category { categoryInDb.Name = category.Name; categoryInDb.Description = category.Description; _context.Update(category); TempData["Success"] = "Update Successful"; return(RedirectToAction("Index")); } if (category.MainAccountCategory == 0) { ModelState.AddModelError("mainGl", "please select a category "); } } var tCategory = new GlCategory { Id = 0 }; return(View("GlCategoryForm", tCategory)); }
public ActionResult Edit([Bind(Include = "ID,Name,Description")] GlCategory glcategory) { if (ModelState.IsValid) { try { //check for unique name string originalName = glCatRepo.GetById(glcategory.ID).Name; if (!glcategory.Name.ToLower().Equals(originalName.ToLower())) //glCategory name has been changed during editting, so check if the new name doesnt exist already { if (!categLogic.IsUniqueName(glcategory.Name)) { ViewBag.Msg = "Please select another name"; return(View()); } } glCatRepo.Update(glcategory); return(RedirectToAction("Index")); } catch (Exception ex) { //ErrorLogger.Log("Message= " + ex.Message + "\nInner Exception= " + ex.InnerException + "\n"); return(PartialView("Error")); } } ViewBag.Msg = "Please enter correct data"; return(View(glcategory)); }
public ActionResult DeleteConfirmed(int id) { GlCategory glCategory = db.GlCategories.Find(id); db.GlCategories.Remove(glCategory); db.SaveChanges(); return(RedirectToAction("Index")); }
public ActionResult New() { var category = new GlCategory { Id = 0 }; return(View("GlCategoryForm", category)); }
// GET: GlCategory/Edit/5 public ActionResult Edit(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } GlCategory glCategory = db.GlCategories.Find(id); if (glCategory == null) { return(HttpNotFound()); } return(View(glCategory)); }
// GET: /GlCategory/Edit/5 public ActionResult Edit(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } GlCategory glcategory = glCatRepo.GetById((int)id); if (glcategory == null) { return(HttpNotFound()); } ViewBag.Msg = ""; return(View(glcategory)); }
public async Task <ActionResult> Create([Bind(Include = "ID,AccountName,CodeNumber,AccountBalance,GlCategoryID,BranchID")] GlAccount glAccount) { if (ModelState.IsValid) { GlCategory glcategory = await db.GlCategories.FindAsync(glAccount.GlCategoryID); glAccount.CodeNumber = Generator.GenerateGLAccountCode(glcategory.MainCategory.ToString()); db.GlAccounts.Add(glAccount); await db.SaveChangesAsync(); return(RedirectToAction("Index")); } ViewBag.BranchID = new SelectList(db.Branches, "Id", "Name", glAccount.BranchID); ViewBag.GlCategoryID = new SelectList(db.GlCategories, "ID", "Name", glAccount.GlCategoryID); return(View(glAccount)); }
protected void Page_Load(object sender, EventArgs e) { DropDownMainAccountCategory.DataSource = Enum.GetNames(typeof(MainAccountCategory)); DropDownMainAccountCategory.DataBind(); if (!IsPostBack) { if (!string.IsNullOrWhiteSpace(Request.QueryString["id"])) { int id = Convert.ToInt32(Request.QueryString["id"]); GlCategory glCategory = Microsoft.Practices.ServiceLocation.ServiceLocator.Current.GetInstance <IGlCategoryDb>() .RetrieveById(id); TextBoxNameGlCategoryName.Value = glCategory.GlCategoryName; TextBoxNameDescription.Value = glCategory.Description; DropDownMainAccountCategory.SelectedValue = glCategory.MainAccountCategory.ToString(); TextBoxId.Value = glCategory.Id.ToString(); } } }
public string GetGlAccountCode(GlAccount glAccount) { //GlAccount glAccount = new GlAccount(); GlCategory glCategory = new GlCategory(); Random Rand = new Random(); string RandString = Convert.ToString(Rand.Next(10000, 99999)); string GlAccountCode = ""; //var tr = Enum.GetValues(typeof(MainAccountCategory)); // int enumId = Convert.ToInt32(tr); switch (glAccount.GlCategory.MainAccountCategory) { case MainAccountCategory.Asset: GlAccountCode = '1' + RandString; break; case MainAccountCategory.Liability: GlAccountCode = '2' + RandString; break; case MainAccountCategory.Capital: GlAccountCode = '3' + RandString; break; case MainAccountCategory.Income: GlAccountCode = '4' + RandString; break; case MainAccountCategory.Expense: GlAccountCode = '5' + RandString; break; } glAccount.GlAccountCodes = GlAccountCode; return(glAccount.GlAccountCodes); }
public ActionResult Edit([Bind(Include = "ID,Name,Description,MainCategory")] GlCategory glCategory) { if (ModelState.IsValid) { try { // original category is automatically being tracked by the db context. (because it was read from database, tracked with Unchanged status) // its causing conflict when i track glCategory built by the model binder because they have the same primary key. // my solution is to detach originalCategory from context tracking. GlCategory originalCategory = db.GlCategories.Find(glCategory.ID); db.Entry(originalCategory).State = EntityState.Detached; string originalName = originalCategory.Name; if (!glCategory.Name.ToLower().Equals(originalName.ToLower())) { if (!glCatLogic.IsUniqueName(glCategory.Name)) { AddError("Please select another name"); return(View(glCategory)); } } db.Entry(glCategory).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } catch (Exception ex) { AddError(ex.ToString()); return(View(glCategory)); } } AddError("Please enter valid data"); return(View(glCategory)); }
public void Save(GlCategory category) { _db.Add(category); _db.Save(category); }
protected void searchsubmit_OnServerClick(object sender, EventArgs e) { try { if (string.IsNullOrWhiteSpace(TextBoxNameGlCategoryName.Value)) { throw new Exception("Gl Category Name field is required"); } if (string.IsNullOrWhiteSpace(TextBoxNameDescription.Value)) { throw new Exception("Description field is required"); } if (string.IsNullOrWhiteSpace(TextBoxId.Value)) { GlCategory glCategory = new GlCategory(); glCategory.GlCategoryName = TextBoxNameGlCategoryName.Value; glCategory.Description = TextBoxNameDescription.Value; glCategory.MainAccountCategory = (MainAccountCategory)Enum.Parse(typeof(MainAccountCategory), DropDownMainAccountCategory.SelectedValue); glCategory.DateAdded = DateTime.Now; glCategory.DateUpdated = DateTime.Now; Microsoft.Practices.ServiceLocation.ServiceLocator.Current.GetInstance <IGlCategoryDb>().InsertData(glCategory); } else { GlCategory glCategory = Microsoft.Practices.ServiceLocation.ServiceLocator.Current.GetInstance <IGlCategoryDb>() .RetrieveById(Convert.ToInt32(TextBoxId.Value)); glCategory.GlCategoryName = TextBoxNameGlCategoryName.Value; glCategory.Description = TextBoxNameDescription.Value; glCategory.MainAccountCategory = (MainAccountCategory)Enum.Parse(typeof(MainAccountCategory), DropDownMainAccountCategory.SelectedValue); //DropDownMainAccountCategory.Enabled = false; glCategory.DateUpdated = DateTime.Now; Microsoft.Practices.ServiceLocation.ServiceLocator.Current.GetInstance <IGlCategoryDb>() .UpdateData(glCategory); } TextBoxNameGlCategoryName.Value = String.Empty; TextBoxNameDescription.Value = String.Empty; if (!Page.ClientScript.IsClientScriptBlockRegistered(this.GetType(), "message")) { Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "message", "<script type='text/javascript'>alertify.alert('Message', '" + "Gl Category Saved Successfully" + "', function(){location = '/GlCategoryMgt/AddNewGlCategory.aspx';});</script>", false); } } catch (Exception ex) { IList <GlCategory> glcategory = Microsoft.Practices.ServiceLocation.ServiceLocator.Current.GetInstance <IGlCategoryDb>().RetrieveAll(); foreach (var glcategorytest in glcategory) { if (TextBoxNameGlCategoryName.Value == glcategorytest.GlCategoryName) { Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "message", "<script type='text/javascript'>alertify.alert('Message', '" + "Gl Catgeory Name Already Exists. Change it" + "', function(){});</script>", false); } } if (DropDownMainAccountCategory.SelectedValue == "0") { Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "message", "<script type='text/javascript'>alertify.alert('Message', '" + "Main Account Category Not Selected. Please Select One " + "', function(){});</script>", false); } string errorMessage = ex.InnerException == null ? ex.Message : ex.InnerException.Message; if (!Page.ClientScript.IsClientScriptBlockRegistered(this.GetType(), "message")) { Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "message", @"<script type='text/javascript'>alertify.alert('Message', """ + errorMessage.Replace("\n", "").Replace("\r", "") + @""", function(){});</script>", false); } } }
protected void searchsubmit_OnServerClick(object sender, EventArgs e) { var tr = Enum.Parse(typeof(MainAccountCategory), DropDownGlCategory.SelectedValue); int categoryID = (int)tr; GlCategory glCategory = Microsoft.Practices.ServiceLocation.ServiceLocator.Current.GetInstance <IGlCategoryDb>() .RetrieveById(categoryID); try { if (string.IsNullOrWhiteSpace(TextBoxNameGlAccountName.Value)) { throw new Exception("Gl Account Name field is required"); } if (string.IsNullOrWhiteSpace(TextBoxId.Value)) { GlAccount glAccount = new GlAccount(); Branch branch = new Branch(); glAccount.Branch = branch; GlAccountLogic glAccountLogic = new GlAccountLogic(); glAccount.GlAccountName = TextBoxNameGlAccountName.Value; string glBranchId = DropDownBranch.SelectedValue; glAccount.Branch.Id = int.Parse(glBranchId); glAccount.Branch.BranchName = Convert.ToString(glAccount.Branch.Id); glAccount.GlCategory = glCategory; glAccount.GlAccountCodes = glAccountLogic.GetGlAccountCode(glAccount); glAccount.DateAdded = DateTime.Now; glAccount.DateUpdated = DateTime.Now; Microsoft.Practices.ServiceLocation.ServiceLocator.Current.GetInstance <IGlAccountDb>().InsertData(glAccount); } else { GlAccount glAccount = Microsoft.Practices.ServiceLocation.ServiceLocator.Current.GetInstance <IGlAccountDb>() .RetrieveById(Convert.ToInt32(TextBoxId.Value)); glAccount.GlAccountName = TextBoxNameGlAccountName.Value; glAccount.GlAccountName = TextBoxNameGlAccountName.Value; //glAccount.GlCategory.Id = int.Parse(DropDownGlCategory.SelectedValue); //glAccount.GlCategory.GlCategoryName = DropDownGlCategory.SelectedValue; GlAccountLogic glAccountLogic = new GlAccountLogic(); glAccount.GlAccountCodes = glAccountLogic.GetGlAccountCode(glAccount); glAccount.GlCategory = glCategory; glAccount.Branch.Id = int.Parse(DropDownBranch.SelectedValue); glAccount.Branch.BranchName = DropDownBranch.SelectedValue; glAccount.DateUpdated = DateTime.Now; Microsoft.Practices.ServiceLocation.ServiceLocator.Current.GetInstance <IGlAccountDb>() .UpdateData(glAccount); } TextBoxNameGlAccountName.Value = String.Empty; if (!Page.ClientScript.IsClientScriptBlockRegistered(this.GetType(), "message")) { Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "message", "<script type='text/javascript'>alertify.alert('Message', '" + "Gl Account Saved Successfully" + "', function(){location = '/GlAccountMgt/AddNewGlAccount.aspx';});</script>", false); } } catch (Exception ex) { IList <GlAccount> glaccount = Microsoft.Practices.ServiceLocation.ServiceLocator.Current.GetInstance <IGlAccountDb>().RetrieveAll(); foreach (var glaccounttest in glaccount) { if (TextBoxNameGlAccountName.Value == glaccounttest.GlAccountName) { Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "message", "<script type='text/javascript'>alertify.alert('Message', '" + "Gl Account Name Already Exists. Change it" + "', function(){});</script>", false); } } if (DropDownGlCategory.SelectedValue == "0") { Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "message", "<script type='text/javascript'>alertify.alert('Message', '" + "Gl Category Not Selected. Please Select One " + "', function(){});</script>", false); } if (DropDownBranch.SelectedValue == "0") { Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "message", "<script type='text/javascript'>alertify.alert('Message', '" + "Branch Not Selected. Please Select a Branch " + "', function(){});</script>", false); } string errorMessage = ex.InnerException == null ? ex.Message : ex.InnerException.Message; if (!Page.ClientScript.IsClientScriptBlockRegistered(this.GetType(), "message")) { Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "message", @"<script type='text/javascript'>alertify.alert('Message', """ + errorMessage.Replace("\n", "").Replace("\r", "") + @""", function(){});</script>", false); } } }
public void Update(GlCategory category) { _db.Save(category); }