public ActionResult saveProfile(AccIndexer form)
        {
            if (!ModelState.IsValid)
            {
                return(View("editU", form));
            }
            else
            {
                var profile = _content.Users.SingleOrDefault(m => m.Id.ToString() == form.ApplicationUser.Id.ToString()); //To load selected user details from the database.
                if (profile == null)                                                                                      //To verify that profile exist
                {
                    TempData["Error"] = "User Profile Does not exist.";                                                   //To display an error message to the user
                    return(View("editU", form));
                }
                else
                {
                    //To update user details
                    profile.Branch      = form.ApplicationUser.Branch;
                    profile.homeAddress = form.ApplicationUser.homeAddress;
                    profile.fullName    = form.ApplicationUser.fullName;
                    profile.Email       = form.ApplicationUser.Email;
                    profile.PhoneNumber = form.ApplicationUser.PhoneNumber;

                    _content.SaveChanges();     //To save update changes to database
                }
            }
            TempData["Success"] = "Update Successful";
            return(RedirectToAction("Index", "Users"));
        }
        public void  DeleteAccount(int id)
        {
            var acctInDB    = _content.customAccts.SingleOrDefault(m => m.id == id);
            var savingsAcct = _content.acctIndex.SingleOrDefault(m => m.id == 1);
            var currentAcct = _content.acctIndex.SingleOrDefault(m => m.id == 3);

            if (acctInDB == null)
            {
                throw new HttpRequestException(HttpStatusCode.NotFound.ToString());
            }
            else
            {
                _content.customAccts.Remove(acctInDB);

                if (acctInDB.customerAccountType == savingsAcct.accountName)
                {
                    var interestAcct = _content.SIlog.SingleOrDefault(m => m.customerAccNumb == acctInDB.customerAccountNumber && m.customerAcctype == acctInDB.customerAccountType);
                    if (interestAcct != null)
                    {
                        _content.SIlog.Remove(interestAcct);
                    }
                }

                if (acctInDB.customerAccountType == currentAcct.accountName)
                {
                    var interestAcct = _content.CIlog.SingleOrDefault(m => m.customerAccNumb == acctInDB.customerAccountNumber && m.customerAcctype == acctInDB.customerAccountType);
                    if (interestAcct != null)
                    {
                        _content.CIlog.Remove(interestAcct);
                    }
                }
            }

            _content.SaveChanges();
        }
 public ActionResult CreateCategoryGL(AccIndexer form)
 {
     if (!ModelState.IsValid)
     {
         return(View("CreateSubCategory", form));     //Return View if model state is not valid with the form contents.
     }
     else
     {
         var checkName = _content.subCategory.SingleOrDefault(m => m.categoryName == form.SubCategory.categoryName);
         if (checkName != null)
         {
             TempData["Error"] = "Sorry Category Name already exists in the database.";
             return(View("CreateSubCategory", form));
         }
         _content.subCategory.Add(form.SubCategory);                //Add new GL Category to database.
         _content.SaveChanges();                                    //Save Changes to database.
         TempData["Success"] = "GL Category Created Successfully!"; //Display Success message to user.
         return(RedirectToAction("ViewSubGL", "Accounts"));         //To return view back to the index page.
     }
 }
Exemplo n.º 4
0
        public void DeleteAccount(int id)
        {
            var acctInDB = _content.closedAcct.SingleOrDefault(m => m.id == id);

            if (acctInDB == null)
            {
                throw new HttpRequestException(HttpStatusCode.NotFound.ToString());
            }
            else
            {
                _content.closedAcct.Remove(acctInDB);
            }

            _content.SaveChanges();
        }
        public void DeleteCustomer(int id)
        {
            var customerInDB = _content.custom.SingleOrDefault(m => m.id.ToString() == id.ToString());
            var savingsAcct  = _content.acctIndex.SingleOrDefault(m => m.id == 1);
            var currentAcct  = _content.acctIndex.SingleOrDefault(m => m.id == 3);

            if (customerInDB == null)
            {
                throw new HttpRequestException(HttpStatusCode.NotFound.ToString());
            }
            else
            {
                var customerAccountsInDB = _content.customAccts.ToList();
                foreach (var item in customerAccountsInDB)
                {
                    if (item.CustomerID == customerInDB.id)
                    {
                        if (item.customerAccountType == savingsAcct.accountName)
                        {
                            var interestAcct = _content.SIlog.SingleOrDefault(m => m.customerAccNumb == item.customerAccountNumber && m.customerAcctype == item.customerAccountType);
                            if (interestAcct != null)
                            {
                                _content.SIlog.Remove(interestAcct);
                            }
                        }

                        if (item.customerAccountType == currentAcct.accountName)
                        {
                            var interestAcct = _content.CIlog.SingleOrDefault(m => m.customerAccNumb == item.customerAccountNumber && m.customerAcctype == item.customerAccountType);
                            if (interestAcct != null)
                            {
                                _content.CIlog.Remove(interestAcct);
                            }
                        }

                        _content.customAccts.Remove(item);
                    }
                }

                _content.custom.Remove(customerInDB);
            }

            _content.SaveChanges();
        }
 public ActionResult CreateProfilee(AccIndexer form)
 {
     if (!ModelState.IsValid)
     {
         TempData["Error"] = "Error Creating Customer Profile,pls check inputs and try again.";  //Displaying Error message to the user.
         return(RedirectToAction("CreateProfile", "Customers"));
     }
     else
     {
         var checkName = _content.custom.SingleOrDefault(m => m.customerName == form.Customer.customerName);
         if (checkName != null)
         {
             TempData["Error"] = "Customer Name Already exists in the database.";    //Displaying Error message to the user.
             return(View("CreateProfile", form));
         }
         var checkEmail = _content.custom.SingleOrDefault(m => m.customerEmail == form.Customer.customerEmail);  //To check that customer email doesn't already exist in the database.
         if (checkEmail != null)
         {
             TempData["Error"] = "Customer Email Already exists in the database, pls use another email.";    //Displaying Error message to the user.
             return(View("CreateProfile", form));
         }
         //To add new customer profile to the database
         _content.custom.Add(form.Customer);
         _content.SaveChanges();
         TempData["Success"] = "Customer Profile Created Successfully";   //Displaying Success message to the user.
         return(RedirectToAction("Index", "Customers"));
     }
 }