Exemplo n.º 1
0
        // GET: Services/Edit/5
        public ActionResult Edit(int?id)
        {
            try
            {
                if (id == null)
                {
                    TempData["Toastr"] = Toastr.BadRequest;
                    return(RedirectToAction("Index"));
                }
                var service = _db.ServiceInfos.Find(id);
                if (service == null)
                {
                    TempData["Toastr"] = Toastr.HttpNotFound;
                    return(RedirectToAction("Index"));
                }
                ViewBag.StatusList = Common.ToSelectList <Status>(service.Status);

                return(View(service));
            }
            catch (Exception ex)
            {
                TempData["Toastr"] = Toastr.DbError(ex.Message);
                return(RedirectToAction("Index"));
            }
        }
Exemplo n.º 2
0
        public ActionResult Create(Group group)
        {
            using (var dbTransaction = _db.Database.BeginTransaction())
            {
                try
                {
                    if (!ModelState.IsValid)
                    {
                        return(View(group));
                    }
                    if (_db.Groups.Any(x => x.Name == group.Name))
                    {
                        ModelState.AddModelError("Name", @"Group Name already exist, try another.");
                        return(View(group));
                    }
                    _db.Groups.Add(group);
                    _db.SaveChanges();
                    dbTransaction.Commit();

                    TempData["Toastr"] = Toastr.Added;
                    return(RedirectToAction("Index"));
                }
                catch (Exception ex)
                {
                    dbTransaction.Rollback();
                    TempData["Toastr"] = Toastr.DbError(ex.Message);
                    return(RedirectToAction("Index"));
                }
            }
        }
Exemplo n.º 3
0
 public ActionResult DeleteConfirmed(int?id)
 {
     using (var dbTransaction = _db.Database.BeginTransaction())
     {
         try
         {
             if (id == null)
             {
                 TempData["Toastr"] = Toastr.BadRequest;
                 return(RedirectToAction("Index"));
             }
             var clientInfo = _db.ClientInfos.Find(id);
             if (clientInfo == null)
             {
                 TempData["Toastr"] = Toastr.HttpNotFound;
                 return(RedirectToAction("Index"));
             }
             _db.ClientInfos.Remove(clientInfo);
             _db.SaveChanges();
             dbTransaction.Commit();
             TempData["Toastr"] = Toastr.Deleted;
             return(RedirectToAction("Index"));
         }
         catch (Exception ex)
         {
             dbTransaction.Rollback();
             TempData["Toastr"] = Toastr.DbError(ex.Message);
             return(RedirectToAction("Index"));
         }
     }
 }
Exemplo n.º 4
0
        // GET: Suppliers/Details/5
        public ActionResult Details(int?id)
        {
            try
            {
                if (id == null)
                {
                    TempData["Toastr"] = Toastr.BadRequest;
                    return(RedirectToAction("Index"));
                }
                var suppliersInfo = _db.SuppliersInfos.Find(id);

                if (suppliersInfo != null)
                {
                    return(View(suppliersInfo));
                }

                TempData["Toastr"] = Toastr.HttpNotFound;
                return(RedirectToAction("Index"));
            }
            catch (Exception ex)
            {
                TempData["Toastr"] = Toastr.DbError(ex.Message);
                return(RedirectToAction("Index"));
            }
        }
Exemplo n.º 5
0
        public ActionResult Create([Bind(Include = "Id,SupplierName,SupplierEmail,SupplierPhone,SupplierAddress,SupplierMobileNo")] SuppliersInfo supplier)
        {
            using (var dbTransaction = _db.Database.BeginTransaction())
            {
                try
                {
                    ModelState.Clear();
                    supplier.SupplierId = string.Format("SI-{0:000000}", _db.SuppliersInfos.Count() + 1);
                    supplier.EntryBy    = _db.Users.First(x => x.UserName == User.Identity.Name).Id;
                    supplier.EntryDate  = DateTime.Now;
                    TryValidateModel(supplier);
                    if (ModelState.IsValid)
                    {
                        _db.SuppliersInfos.Add(supplier);
                        _db.SaveChanges();

                        dbTransaction.Commit();
                        TempData["Toastr"] = Toastr.Added;

                        return(RedirectToAction("Index"));
                    }
                    dbTransaction.Rollback();
                    return(View(supplier));
                }
                catch (Exception ex)
                {
                    dbTransaction.Rollback();
                    TempData["Toastr"] = Toastr.DbError(ex.Message);
                    return(RedirectToAction("Index"));
                }
            }
        }
Exemplo n.º 6
0
        public ActionResult Create([Bind(Include = "Id,MethodName")] PaymentMethod paymentMethod)
        {
            using (var dbTransaction = _db.Database.BeginTransaction())
            {
                try
                {
                    ModelState.Clear();
                    paymentMethod.MethodId  = string.Format("PI-{0:000000}", _db.PaymentMethods.Count() + 1);
                    paymentMethod.EntryBy   = _db.Users.First(x => x.UserName == User.Identity.Name).Id;
                    paymentMethod.EntryDate = DateTime.Now;
                    TryValidateModel(paymentMethod);
                    if (ModelState.IsValid)
                    {
                        _db.PaymentMethods.Add(paymentMethod);
                        _db.SaveChanges();

                        dbTransaction.Commit();
                        TempData["Toastr"] = Toastr.Added;

                        return(RedirectToAction("Index"));
                    }
                    dbTransaction.Rollback();
                    return(View(paymentMethod));
                }
                catch (Exception ex)
                {
                    dbTransaction.Rollback();
                    TempData["Toastr"] = Toastr.DbError(ex.Message);
                    return(RedirectToAction("Index"));
                }
            }
        }
Exemplo n.º 7
0
 // GET: Employees/Details/5
 public ActionResult Details(int?id)
 {
     try
     {
         if (id == null)
         {
             TempData["Toastr"] = Toastr.BadRequest;
             return(RedirectToAction("Index"));
         }
         var employee = _db.EmployeeBasicInfos.Find(id);
         if (employee == null)
         {
             TempData["Toastr"] = Toastr.HttpNotFound;
             return(RedirectToAction("Index"));
         }
         var imageToShow = !string.IsNullOrWhiteSpace(employee.ImageUrl) ? employee.ImageUrl : "/Content/template/img/avatars/default.png";
         ViewBag.Designations = new SelectList(_db.EmployeeDesignations, "Id", "DesignationTitleEn", employee.EmployeeDesignationId);
         ViewBag.BloodGroups  = Common.ToSelectList <BloodGroup>(employee.BloodGroup);
         ViewBag.Levels       = Common.ToSelectList <EmployeeLevel>(employee.UserLevel);
         ViewBag.Image        = System.IO.File.Exists(Server.MapPath("~" + imageToShow)) ? imageToShow : "";
         return(View(employee));
     }
     catch (Exception ex)
     {
         TempData["Toastr"] = Toastr.DbError(ex.Message);
         return(RedirectToAction("Index"));
     }
 }
Exemplo n.º 8
0
        // GET: Navigation/Edit/5
        public ActionResult Edit(int?id)
        {
            try
            {
                if (id == null)
                {
                    TempData["Toastr"] = Toastr.BadRequest;
                    return(RedirectToAction("Index"));
                }
                var menu = _db.Menus.Find(id);
                if (menu == null)
                {
                    TempData["Toastr"] = Toastr.HttpNotFound;
                    return(RedirectToAction("Index"));
                }
                ViewBag.Modules    = Common.ToSelectList <Module>(menu.ModuleName);
                ViewBag.StatusList = Common.ToSelectList <Status>(menu.Status);

                return(View(menu));
            }
            catch (Exception ex)
            {
                TempData["Toastr"] = Toastr.DbError(ex.Message);
                return(RedirectToAction("Index"));
            }
        }
Exemplo n.º 9
0
        // GET: PaymentMethods/Details/5
        public ActionResult Details(int?id)
        {
            try
            {
                if (id == null)
                {
                    TempData["Toastr"] = Toastr.BadRequest;
                    return(RedirectToAction("Index"));
                }
                var paymentMethod = _db.PaymentMethods.Find(id);

                if (paymentMethod != null)
                {
                    return(View(paymentMethod));
                }

                TempData["Toastr"] = Toastr.HttpNotFound;
                return(RedirectToAction("Index"));
            }
            catch (Exception ex)
            {
                TempData["Toastr"] = Toastr.DbError(ex.Message);
                return(RedirectToAction("Index"));
            }
        }
Exemplo n.º 10
0
        public ActionResult Create([Bind(Include = "CountryName,CountryCode,DelStatus")] Country country)
        {
            using (var dbTransaction = _db.Database.BeginTransaction())
            {
                try
                {
                    ModelState.Clear();
                    country.EntryBy   = _db.Users.First(x => x.UserName == User.Identity.Name).Id;
                    country.EntryDate = DateTime.Now;
                    TryValidateModel(country);
                    if (ModelState.IsValid)
                    {
                        _db.Countries.Add(country);
                        _db.SaveChanges();

                        dbTransaction.Commit();
                        TempData["Toastr"] = Toastr.Added;

                        return(RedirectToAction("Index"));
                    }
                    dbTransaction.Rollback();
                    return(View(country));
                }
                catch (Exception ex)
                {
                    dbTransaction.Rollback();
                    TempData["Toastr"] = Toastr.DbError(ex.Message);
                    return(RedirectToAction("Index"));
                }
                finally
                {
                    ViewBag.Status = Common.ToSelectList <Status>();
                }
            }
        }
Exemplo n.º 11
0
        public ActionResult CreateDbBackUp()
        {
            try
            {
                var connectionString = WebConfigurationManager.ConnectionStrings["CrmDbContext"].ConnectionString;
                var builder          = new SqlConnectionStringBuilder(connectionString);
                var databaseName     = builder.InitialCatalog;

                var backUpDirectory = Server.MapPath("~/Backup/");
                var fileName        = "CRM_" + DateTime.Now.ToString("yyyy-MM-dd HH.mm.ss") + ".bak";
                var backupPath      = Path.Combine(backUpDirectory, fileName);
                if (!Directory.Exists(backUpDirectory))
                {
                    Directory.CreateDirectory(backUpDirectory);
                }
                foreach (var file in Directory.GetFiles(backUpDirectory, "*.bak").Where(item => item.EndsWith(".bak")))
                {
                    System.IO.File.Delete(file);
                }

                var query = string.Format("BACKUP DATABASE [{0}] TO DISK ='{1}'", databaseName, backupPath);
                _db.Database.ExecuteSqlCommand(TransactionalBehavior.DoNotEnsureTransaction, query);

                var fileBytes = System.IO.File.ReadAllBytes(backupPath);
                return(File(fileBytes, System.Net.Mime.MediaTypeNames.Application.Octet, fileName));
            }
            catch (Exception ex)
            {
                TempData["Toastr"] = Toastr.DbError(ex.Message);
                return(RedirectToAction("Index"));
            }
        }
Exemplo n.º 12
0
        public ActionResult DeleteConfirmed(int?countryId)
        {
            using (var dbTransaction = _db.Database.BeginTransaction())
            {
                try
                {
                    if (countryId == null)
                    {
                        TempData["Toastr"] = Toastr.BadRequest;
                        return(RedirectToAction("Index"));
                    }
                    if (!_db.Countries.Any(x => x.Id == countryId))
                    {
                        TempData["Toastr"] = Toastr.HttpNotFound;
                        return(RedirectToAction("Index"));
                    }

                    _db.Countries
                    .Where(x => x.Id == countryId)
                    .Update(u => new Country
                    {
                        DelStatus = true
                    });
                    dbTransaction.Commit();
                    TempData["Toastr"] = Toastr.Deleted;
                    return(RedirectToAction("Index"));
                }
                catch (Exception ex)
                {
                    dbTransaction.Rollback();
                    TempData["Toastr"] = Toastr.DbError(ex.Message);
                    return(RedirectToAction("Index"));
                }
            }
        }
Exemplo n.º 13
0
        // GET: Groups/Edit/5
        public ActionResult Edit(int?id)
        {
            try
            {
                if (id == null)
                {
                    TempData["Toastr"] = Toastr.BadRequest;
                    return(RedirectToAction("Index"));
                }
                var group = _db.Groups.Find(id);
                ViewBag.IsGroupIsAdmin = _db.Groups.Any(x => x.Id == id && x.Name.ToLower() == "admin");
                if (group != null)
                {
                    return(View(group));
                }

                TempData["Toastr"] = Toastr.HttpNotFound;
                return(RedirectToAction("Index"));
            }
            catch (Exception ex)
            {
                TempData["Toastr"] = Toastr.DbError(ex.Message);
                return(RedirectToAction("Index"));
            }
        }
Exemplo n.º 14
0
 public ActionResult Edit(int?id)
 {
     try
     {
         if (id == null)
         {
             TempData["Toastr"] = Toastr.BadRequest;
             return(RedirectToAction("Index"));
         }
         var client = _db.ClientInfos.Find(id);
         if (client == null)
         {
             TempData["Toastr"] = Toastr.HttpNotFound;
             return(RedirectToAction("Index"));
         }
         ViewBag.StatusList          = Common.ToSelectList <Status>();
         ViewBag.BranchList          = new SelectList(_db.BranchInfos, "Id", "BranchName", client.BranchId);
         ViewBag.ReferralTypes       = Common.ToSelectList <ReferralsType>(client.ReferralType);
         ViewBag.IsRequireSupplier   = Common.ToSelectList <RequireSuppiler>(client.SupplierId == null ? (int)RequireSuppiler.No : (int)RequireSuppiler.Yes);
         ViewBag.ServiceList         = new SelectList(_db.ServiceInfos.OrderBy(x => x.ServiceName), "Id", "ServiceName", client.ServiceId);
         ViewBag.WorkingStatusList   = Common.ToSelectList <WorkingStatus>(client.WorkingStatus);
         ViewBag.SmsConfirmationList = Common.ToSelectList <SmsConfirmation>(client.SmsConfirmation);
         ViewBag.InfoStatusList      = Common.ToSelectList <InformationUpdate>(client.InfoStatus);
         ViewBag.DeliveryStatusList  = Common.ToSelectList <DeliveryStatus>(client.DeliveryStatus);
         ViewBag.StatusList          = Common.ToSelectList <Status>(client.Status);
         return(View(client));
     }
     catch (Exception ex)
     {
         TempData["Toastr"] = Toastr.DbError(ex.Message);
         return(RedirectToAction("Index"));
     }
 }
Exemplo n.º 15
0
        public ActionResult Create(Menu menu)
        {
            using (var dbTransaction = _db.Database.BeginTransaction())
            {
                try
                {
                    if (!ModelState.IsValid)
                    {
                        dbTransaction.Dispose();
                        ViewBag.Modules    = Common.ToSelectList <Module>();
                        ViewBag.StatusList = Common.ToSelectList <Status>();
                        return(View(menu));
                    }
                    _db.Menus.Add(menu);
                    _db.SaveChanges();
                    dbTransaction.Commit();

                    TempData["Toastr"] = Toastr.Added;
                    return(RedirectToAction("Index"));
                }
                catch (Exception ex)
                {
                    dbTransaction.Rollback();
                    TempData["Toastr"] = Toastr.DbError(ex.Message);
                    return(RedirectToAction("Index"));
                }
            }
        }
Exemplo n.º 16
0
        public ActionResult Edit([Bind(Include = "Id,DesignationTitleEn,DesignationTitleBn,DesignationDepertment,Status")] EmployeeDesignation designation, int?id)
        {
            using (var dbTransaction = _db.Database.BeginTransaction())
            {
                try
                {
                    if (id == null)
                    {
                        TempData["Toastr"] = Toastr.HttpNotFound;
                        return(RedirectToAction("Index"));
                    }
                    if (_db.EmployeeDesignations.Count(x => x.Id == id) < 1)
                    {
                        TempData["Toastr"] = Toastr.HttpNotFound;
                        return(RedirectToAction("Index"));
                    }
                    var empDesignation = _db.EmployeeDesignations.Single(x => x.Id == id);
                    if (empDesignation == null)
                    {
                        TempData["Toastr"] = Toastr.HttpNotFound;
                        return(RedirectToAction("Index"));
                    }

                    ModelState.Clear();
                    designation.DesignationId = empDesignation.DesignationId;
                    designation.EntryBy       = empDesignation.EntryBy;
                    designation.EntryDate     = empDesignation.EntryDate;
                    designation.DelStatus     = empDesignation.DelStatus;
                    TryValidateModel(designation);

                    if (!ModelState.IsValid)
                    {
                        return(View(designation));
                    }

                    _db.EmployeeDesignations
                    .Where(x => x.Id == id)
                    .Update(u => new EmployeeDesignation {
                        DesignationTitleEn = designation.DesignationTitleEn,
                        DesignationTitleBn = designation.DesignationTitleBn,
                        Status             = designation.Status
                    });
                    dbTransaction.Commit();

                    TempData["Toastr"] = Toastr.Updated;
                    return(RedirectToAction("Index"));
                }
                catch (Exception ex)
                {
                    dbTransaction.Rollback();
                    TempData["Toastr"] = Toastr.DbError(ex.Message);
                    return(RedirectToAction("Index"));
                }
                finally
                {
                    ViewBag.StatusList = Common.ToSelectList <Status>(designation.Status);
                }
            }
        }
Exemplo n.º 17
0
        public ActionResult Edit([Bind(Include = "Id,SupplierName,SupplierEmail,SupplierPhone,SupplierAddress,SupplierMobileNo")] SuppliersInfo supplier, int?id)
        {
            using (var dbTransaction = _db.Database.BeginTransaction())
            {
                try
                {
                    if (id == null)
                    {
                        TempData["Toastr"] = Toastr.HttpNotFound;
                        return(RedirectToAction("Index"));
                    }
                    if (_db.SuppliersInfos.Count(x => x.Id == id) < 1)
                    {
                        TempData["Toastr"] = Toastr.HttpNotFound;
                        return(RedirectToAction("Index"));
                    }
                    var suppliersInfo = _db.SuppliersInfos.Single(x => x.Id == id);
                    if (suppliersInfo == null)
                    {
                        TempData["Toastr"] = Toastr.HttpNotFound;
                        return(RedirectToAction("Index"));
                    }

                    ModelState.Clear();
                    supplier.SupplierId = suppliersInfo.SupplierId;
                    supplier.EntryBy    = suppliersInfo.EntryBy;
                    supplier.EntryDate  = suppliersInfo.EntryDate;
                    supplier.DelStatus  = suppliersInfo.DelStatus;

                    TryValidateModel(supplier);

                    if (!ModelState.IsValid)
                    {
                        return(View(supplier));
                    }

                    _db.SuppliersInfos
                    .Where(x => x.Id == id)
                    .Update(u => new SuppliersInfo
                    {
                        SupplierName     = supplier.SupplierName,
                        SupplierEmail    = supplier.SupplierEmail,
                        SupplierPhone    = supplier.SupplierPhone,
                        SupplierAddress  = supplier.SupplierAddress,
                        SupplierMobileNo = supplier.SupplierMobileNo
                    });
                    dbTransaction.Commit();

                    TempData["Toastr"] = Toastr.Updated;
                    return(RedirectToAction("Index"));
                }
                catch (Exception ex)
                {
                    dbTransaction.Rollback();
                    TempData["Toastr"] = Toastr.DbError(ex.Message);
                    return(RedirectToAction("Index"));
                }
            }
        }
Exemplo n.º 18
0
        public ActionResult Edit([Bind(Include = "Id,AccountId,Date,PayerType,Amount,MethodId,PayerId,Description")] DepositViewModel deposit, int?id)
        {
            using (var dbTransaction = _db.Database.BeginTransaction())
            {
                try
                {
                    if (id == null)
                    {
                        TempData["Toastr"] = Toastr.HttpNotFound;
                        return(RedirectToAction("Index"));
                    }

                    if (!_db.TransactionsInfos.Any(x => x.Id == id))
                    {
                        TempData["Toastr"] = Toastr.HttpNotFound;
                        return(RedirectToAction("Index"));
                    }

                    if (!ModelState.IsValid)
                    {
                        return(View(deposit));
                    }
                    var count = _db.TransactionsInfos
                                .Where(x => x.Id == id)
                                .Update(u => new TransactionsInfo
                    {
                        Date        = deposit.Date,
                        AccountTo   = deposit.AccountId,
                        PayerType   = deposit.PayerType,
                        PayerId     = deposit.PayerId,
                        Amount      = deposit.Amount,
                        MethodId    = deposit.MethodId,
                        Description = deposit.Description
                    });
                    if (count > 0)
                    {
                        _db.UpdateBalance(_db.BankAccounts.Find(deposit.AccountId), (double)deposit.Amount);
                    }
                    dbTransaction.Commit();
                    TempData["Toastr"] = Toastr.Updated;

                    return(RedirectToAction("Index"));
                }
                catch (Exception ex)
                {
                    dbTransaction.Rollback();
                    TempData["Toastr"] = Toastr.DbError(ex.Message);
                    return(RedirectToAction("Index"));
                }
                finally
                {
                    ViewBag.Accounts       = new SelectList(_db.BankAccounts.ToList(), "Id", "AccountName", deposit.AccountId);
                    ViewBag.PayerTypes     = Common.ToSelectList <PayerType>(deposit.PayerType);
                    ViewBag.PaymentMethods = new SelectList(_db.PaymentMethods.ToList(), "Id", "MethodName", deposit.MethodId);
                }
            }
        }
Exemplo n.º 19
0
        public ActionResult Edit([Bind(Include = "Id,MethodName")] PaymentMethod paymentMethod, int?id)
        {
            using (var dbTransaction = _db.Database.BeginTransaction())
            {
                try
                {
                    if (id == null)
                    {
                        TempData["Toastr"] = Toastr.HttpNotFound;
                        return(RedirectToAction("Index"));
                    }
                    if (_db.PaymentMethods.Count(x => x.Id == id) < 1)
                    {
                        TempData["Toastr"] = Toastr.HttpNotFound;
                        return(RedirectToAction("Index"));
                    }
                    var method = _db.PaymentMethods.Single(x => x.Id == id);
                    if (method == null)
                    {
                        TempData["Toastr"] = Toastr.HttpNotFound;
                        return(RedirectToAction("Index"));
                    }

                    ModelState.Clear();
                    paymentMethod.MethodId     = method.MethodId;
                    paymentMethod.CurrentValue = method.CurrentValue;
                    paymentMethod.EntryBy      = method.EntryBy;
                    paymentMethod.EntryDate    = method.EntryDate;
                    paymentMethod.DelStatus    = method.DelStatus;

                    TryValidateModel(paymentMethod);

                    if (!ModelState.IsValid)
                    {
                        return(View(paymentMethod));
                    }

                    _db.PaymentMethods
                    .Where(x => x.Id == id)
                    .Update(u => new PaymentMethod {
                        MethodName = paymentMethod.MethodName
                    });
                    dbTransaction.Commit();

                    TempData["Toastr"] = Toastr.Updated;
                    return(RedirectToAction("Index"));
                }
                catch (Exception ex)
                {
                    dbTransaction.Rollback();
                    TempData["Toastr"] = Toastr.DbError(ex.Message);
                    return(RedirectToAction("Index"));
                }
            }
        }
Exemplo n.º 20
0
        public ActionResult Edit([Bind(Include = "Id,BranchName,BranchCode,Status")] BranchInfo branchInfo, int?id)
        {
            using (var dbTransaction = _db.Database.BeginTransaction())
            {
                try
                {
                    if (id == null)
                    {
                        TempData["Toastr"] = Toastr.BadRequest;
                        return(RedirectToAction("Index"));
                    }
                    if (_db.BranchInfos.Count(x => x.Id == id) < 1)
                    {
                        TempData["Toastr"] = Toastr.HttpNotFound;
                        return(RedirectToAction("Index"));
                    }
                    var branch = _db.BranchInfos.Single(x => x.Id == id);

                    ModelState.Clear();

                    branchInfo.BranchId  = branch.BranchId;
                    branchInfo.DelStatus = branch.DelStatus;
                    branchInfo.EntryBy   = branch.EntryBy;
                    branchInfo.EntryDate = branch.EntryDate;

                    TryValidateModel(branchInfo);
                    if (!ModelState.IsValid)
                    {
                        return(View(branchInfo));
                    }

                    _db.BranchInfos
                    .Where(x => x.Id == id)
                    .Update(u => new BranchInfo {
                        BranchName = branchInfo.BranchName,
                        BranchCode = branchInfo.BranchCode,
                        Status     = branchInfo.Status
                    });
                    dbTransaction.Commit();

                    TempData["Toastr"] = Toastr.Updated;
                    return(RedirectToAction("Index"));
                }
                catch (Exception ex)
                {
                    dbTransaction.Rollback();
                    TempData["Toastr"] = Toastr.DbError(ex.Message);
                    return(RedirectToAction("Index"));
                }
                finally
                {
                    ViewBag.StatusList = Common.ToSelectList <Status>(branchInfo.Status);
                }
            }
        }
Exemplo n.º 21
0
        public ActionResult Edit([Bind(Include = "Id,AccountFrom,AccountTo,Date,Amount,MethodId,Description")] TransferViewModel transfer, int?id)
        {
            using (var dbTransaction = _db.Database.BeginTransaction())
            {
                try
                {
                    if (id == null)
                    {
                        TempData["Toastr"] = Toastr.HttpNotFound;
                        return(RedirectToAction("Index"));
                    }
                    if (!_db.TransactionsInfos.Any(x => x.Id == id && x.TransactionType == TransactionType.Transfer))
                    {
                        TempData["Toastr"] = Toastr.HttpNotFound;
                        return(RedirectToAction("Index"));
                    }
                    if (!ModelState.IsValid)
                    {
                        return(View(transfer));
                    }
                    var count = _db.TransactionsInfos
                                .Where(x => x.Id == id)
                                .Update(u => new TransactionsInfo
                    {
                        Date        = transfer.Date,
                        AccountTo   = transfer.AccountTo,
                        AccountFrom = transfer.AccountFrom,
                        Amount      = transfer.Amount,
                        MethodId    = transfer.MethodId,
                        Description = transfer.Description
                    });
                    if (count > 0)
                    {
                        _db.UpdateBalance(_db.BankAccounts.Find(transfer.AccountFrom), (double)transfer.Amount, BalanceMode.Decrement);
                        _db.UpdateBalance(_db.BankAccounts.Find(transfer.AccountTo), (double)transfer.Amount);
                    }
                    dbTransaction.Commit();
                    TempData["Toastr"] = Toastr.Updated;

                    return(RedirectToAction("Index"));
                }
                catch (Exception ex)
                {
                    dbTransaction.Rollback();
                    TempData["Toastr"] = Toastr.DbError(ex.Message);
                    return(RedirectToAction("Index"));
                }
                finally
                {
                    ViewBag.FromAccounts   = new SelectList(_db.BankAccounts.ToList(), "Id", "AccountName", transfer.AccountFrom);
                    ViewBag.ToAccounts     = new SelectList(_db.BankAccounts.ToList(), "Id", "AccountName", transfer.AccountTo);
                    ViewBag.PaymentMethods = new SelectList(_db.PaymentMethods.ToList(), "Id", "MethodName", transfer.MethodId);
                }
            }
        }
Exemplo n.º 22
0
        public ActionResult Create([Bind(Include = "Id,BranchId,ReferralType,AgentId,SupplierId,FirstName,LastName,ContactNo,Referral,ReferralContactNo,ServiceId,AirLineId,OldFlightDate,ChangeFlightDate,AirLinePnr,GdsPnr,NewFlightDate,CollageName,CourseName,EmailAddress,ServiceCharge,Cost,Profit,Discount,DoneBy,WorkingStatus,DeliveryStatus,InfoStatus,Remark,VenueFromId,VenueToId,SmsNo,CountryId")] ClientInfo client)
        {
            using (var dbTransaction = _db.Database.BeginTransaction())
            {
                try
                {
                    ModelState.Clear();
                    var branch = client.BranchId == null?_db.BranchInfos.First(x => x.BranchName == "Head" && x.BranchCode == "main") : _db.BranchInfos.First(x => x.Id == client.BranchId);

                    client.CustomerId = string.Format("{0}{1:000000}{2:MMyy}",
                                                      branch.BranchCode.ToUpper(),
                                                      _db.ClientInfos.Count() + 1,
                                                      DateTime.Now
                                                      );
                    client.EntryBy         = _db.Users.First(x => x.UserName == User.Identity.Name).Id;
                    client.ServedBy        = _db.Users.First(x => x.UserName == User.Identity.Name).Id;
                    client.WorkingStatus   = WorkingStatus.Pending;
                    client.Status          = Status.Inactive;
                    client.InfoStatus      = InformationUpdate.NotUpdated;
                    client.DeliveryStatus  = DeliveryStatus.NotDelivery;
                    client.SmsConfirmation = SmsConfirmation.NotSendingSms;
                    client.EntryDate       = DateTime.Now;
                    //use default branch as head if branch id not selected
                    client.BranchId = branch.Id;
                    client.FullName = client.LastName != null?string.Format("{0} {1}", client.FirstName, client.LastName) : client.FirstName;

                    TryValidateModel(client);

                    if (!ModelState.IsValid)
                    {
                        return(View(client));
                    }
                    _db.ClientInfos.Add(client);
                    _db.SaveChanges();

                    dbTransaction.Commit();
                    TempData["Toastr"] = Toastr.Added;

                    return(RedirectToAction("Index"));
                }
                catch (Exception ex)
                {
                    dbTransaction.Rollback();
                    TempData["Toastr"] = Toastr.DbError(ex.Message);
                    return(RedirectToAction("Index"));
                }
                finally
                {
                    ViewBag.BranchList        = new SelectList(_db.BranchInfos, "Id", "BranchName");
                    ViewBag.ReferralTypes     = Common.ToSelectList <ReferralsType>();
                    ViewBag.IsRequireSupplier = Common.ToSelectList <RequireSuppiler>(RequireSuppiler.No);
                    ViewBag.ServiceList       = new SelectList(_db.ServiceInfos.OrderBy(x => x.ServiceName), "Id", "ServiceName");
                }
            }
        }
Exemplo n.º 23
0
 public ActionResult AgentInfoReport()
 {
     try
     {
         ViewBag.Agents = new SelectList(_db.AgentInfos.ToList(), "Id", "AgentName");
         return(View());
     }
     catch (Exception ex)
     {
         TempData["Toastr"] = Toastr.DbError(ex.Message);
         return(RedirectToAction("Index", "Home"));
     }
 }
Exemplo n.º 24
0
 public ActionResult SupplierPaymentReport()
 {
     try
     {
         ViewBag.Suppliers = new SelectList(_db.SuppliersInfos.ToList(), "Id", "SupplierName");
         return(View());
     }
     catch (Exception ex)
     {
         TempData["Toastr"] = Toastr.DbError(ex.Message);
         return(RedirectToAction("Index", "Home"));
     }
 }
Exemplo n.º 25
0
 // GET: Agents/Create
 public ActionResult Create()
 {
     try
     {
         ViewBag.UserRoleList = new SelectList(_context.Roles.Where(u => !u.Name.Contains("Admin")).ToList(), "Name", "Name");
         ViewBag.StatusList   = Common.ToSelectList <Status>();
         return(View());
     }
     catch (Exception ex)
     {
         TempData["Toastr"] = Toastr.DbError(ex.Message);
         return(RedirectToAction("Index"));
     }
 }
Exemplo n.º 26
0
        public ActionResult Edit(Group model, int?id)
        {
            using (var dbTransaction = _db.Database.BeginTransaction())
            {
                try
                {
                    if (id == null)
                    {
                        TempData["Toastr"] = Toastr.HttpNotFound;
                        return(RedirectToAction("Index"));
                    }
                    if (!ModelState.IsValid)
                    {
                        dbTransaction.Dispose();
                        ViewBag.IsGroupIsAdmin = _db.Groups.Any(x => x.Id == id && x.Name.ToLower() == "admin");
                        return(View(model));
                    }
                    if (!_db.Groups.Any(x => x.Id == id))
                    {
                        TempData["Toastr"] = Toastr.HttpNotFound;
                        return(RedirectToAction("Index"));
                    }
                    var groupName = _db.Groups.Where(x => x.Id == id).Select(x => x.Name).First();
                    _db.Groups
                    .Where(x => x.Id == id)
                    .Update(u => new Group
                    {
                        Name        = groupName.ToLower() == "admin" ? "Admin" : model.Name,
                        Description = model.Description,
                        Account     = model.Account,
                        Billing     = model.Billing,
                        Crm         = model.Crm,
                        Hrm         = groupName.ToLower() == "admin",
                        Report      = model.Report,
                        Setup       = model.Setup
                    });
                    dbTransaction.Commit();

                    TempData["Toastr"] = Toastr.Updated;
                    return(RedirectToAction("Index"));
                }
                catch (Exception ex)
                {
                    dbTransaction.Rollback();
                    TempData["Toastr"] = Toastr.DbError(ex.Message);
                    return(RedirectToAction("Index"));
                }
            }
        }
Exemplo n.º 27
0
        public ActionResult Edit([Bind(Include = "Id,CountryName,CountryCode,DelStatus")] Country country, int?id)
        {
            using (var dbTransaction = _db.Database.BeginTransaction())
            {
                try
                {
                    if (id == null)
                    {
                        TempData["Toastr"] = Toastr.HttpNotFound;
                        return(RedirectToAction("Index"));
                    }
                    if (!_db.Countries.Any(x => x.Id == id))
                    {
                        TempData["Toastr"] = Toastr.HttpNotFound;
                        return(RedirectToAction("Index"));
                    }
                    var data = _db.Countries.Single(x => x.Id == id);

                    ModelState.Clear();

                    country.DelStatus = data.DelStatus;
                    country.EntryBy   = data.EntryBy;
                    country.EntryDate = data.EntryDate;

                    TryValidateModel(country);
                    if (!ModelState.IsValid)
                    {
                        return(View(country));
                    }

                    _db.Countries
                    .Where(x => x.Id == id)
                    .Update(u => new Country {
                        CountryName = country.CountryName,
                        CountryCode = country.CountryCode
                    });
                    dbTransaction.Commit();

                    TempData["Toastr"] = Toastr.Updated;
                    return(RedirectToAction("Index"));
                }
                catch (Exception ex)
                {
                    dbTransaction.Rollback();
                    TempData["Toastr"] = Toastr.DbError(ex.Message);
                    return(RedirectToAction("Index"));
                }
            }
        }
Exemplo n.º 28
0
        public ActionResult Create([Bind(Include = "Id,AccountFrom,AccountTo,Date,Amount,MethodId,Description")] TransferViewModel transfer)
        {
            using (var dbTransaction = _db.Database.BeginTransaction())
            {
                try
                {
                    if (!ModelState.IsValid)
                    {
                        return(View(transfer));
                    }
                    ModelState.Clear();

                    var transaction = new TransactionsInfo();
                    transaction.TransactionId   = string.Format("DI-{0:000000}", _db.TransactionsInfos.Count(x => x.TransactionType == TransactionType.Deposit || x.TransactionType == TransactionType.Transfer) + 1);
                    transaction.TransactionType = TransactionType.Transfer;
                    transaction.Date            = transfer.Date;
                    transaction.AccountTo       = transfer.AccountTo;
                    transaction.AccountFrom     = transfer.AccountFrom;
                    transaction.Amount          = transfer.Amount;
                    transaction.MethodId        = transfer.MethodId;
                    transaction.Description     = transfer.Description;

                    _db.TransactionsInfos.Add(transaction);
                    if (_db.SaveChanges() > 0)
                    {
                        _db.UpdateBalance(_db.BankAccounts.Find(transfer.AccountFrom), (double)transfer.Amount, BalanceMode.Decrement);
                        _db.UpdateBalance(_db.BankAccounts.Find(transfer.AccountTo), (double)transfer.Amount);
                    }

                    dbTransaction.Commit();
                    TempData["Toastr"] = Toastr.Added;

                    return(RedirectToAction("Index"));
                }
                catch (Exception ex)
                {
                    dbTransaction.Rollback();
                    TempData["Toastr"] = Toastr.DbError(ex.Message);
                    return(RedirectToAction("Index"));
                }
                finally
                {
                    var accounts = new SelectList(_db.BankAccounts.ToList(), "Id", "AccountName");
                    ViewBag.FromAccounts   = accounts;
                    ViewBag.ToAccounts     = accounts;
                    ViewBag.PaymentMethods = new SelectList(_db.PaymentMethods.ToList(), "Id", "MethodName");
                }
            }
        }
Exemplo n.º 29
0
 // GET: Employees/Create
 public ActionResult Create()
 {
     try
     {
         ViewBag.Designations = new SelectList(_db.EmployeeDesignations, "Id", "DesignationTitleEn");
         ViewBag.BloodGroups  = Common.ToSelectList <BloodGroup>();
         ViewBag.Levels       = Common.ToSelectList <EmployeeLevel>();
         return(View());
     }
     catch (Exception ex)
     {
         TempData["Toastr"] = Toastr.DbError(ex.Message);
         return(RedirectToAction("Index"));
     }
 }
Exemplo n.º 30
0
        public ActionResult Create([Bind(Include = "Id,OfficeName,AgentName,ContactName,MobileNo,Address,OfficeNo,FaxNo,Email,UserName,Password")] AgentInfo agent)
        {
            using (var transaction = new TransactionScope(TransactionScopeAsyncFlowOption.Enabled))
            {
                try
                {
                    ModelState.Clear();
                    agent.AgentId   = string.Format("AI-{0:000000}", _db.AgentInfos.Count() + 1);
                    agent.EntryBy   = _db.Users.First(x => x.UserName == User.Identity.Name).Id;
                    agent.EntryDate = DateTime.Now;
                    TryValidateModel(agent);
                    if (ModelState.IsValid)
                    {
                        var user = new ApplicationUser {
                            Email = agent.Email, UserName = agent.UserName
                        };
                        var ack = _userManager.Create(user, agent.Password);
                        if (!ack.Succeeded)
                        {
                            transaction.Complete();
                            return(View(agent));
                        }
                        _userManager.AddToRole(user.Id, "Agent");

                        _db.AgentInfos.Add(agent);
                        _db.SaveChanges();

                        transaction.Complete();
                        TempData["Toastr"] = Toastr.Added;

                        return(RedirectToAction("Index"));
                    }
                    Transaction.Current.Rollback();
                    return(View(agent));
                }
                catch (Exception ex)
                {
                    Transaction.Current.Rollback();
                    TempData["Toastr"] = Toastr.DbError(ex.Message);
                    return(RedirectToAction("Index"));
                }
                finally
                {
                    ViewBag.StatusList = Common.ToSelectList <Status>();
                }
            }
        }