public ActionResult IndexAssetRegister()
        {
            ViewBag.AllowAdd    = this.HasPermission(ControllerName.AssetManagement + "-CreateAssetRegister");
            ViewBag.AllowEdit   = this.HasPermission(ControllerName.AssetManagement + "-EditAssetRegister");
            ViewBag.AllowDelete = this.HasPermission(ControllerName.AssetManagement + "-DeleteAssetRegister");

            DataTable dtGetAssetName = AssetDefinitionBI.GetAssetDefinition();

            ViewData["AssetName"] = General.DataTableToSelectList(dtGetAssetName, "AssetDefinitionId", "AssetName", "0", TopEmptyItem: new SelectListItem {
                Value = "0", Text = ""
            });

            DataTable dtGetSupplier = SuppliersBI.GetSuppliers();

            ViewData["SupplierName"] = General.DataTableToSelectList(dtGetSupplier, "SupplierId", "SupplierFullName", "0", TopEmptyItem: new SelectListItem {
                Value = "0", Text = ""
            });

            DataTable dtGetLocation = LocationBI.GetLocation();

            ViewData["LocationName"] = General.DataTableToSelectList(dtGetLocation, "LocationId", "LocationName", "0", TopEmptyItem: new SelectListItem {
                Value = "0", Text = ""
            });

            DataTable dtGetDepartment = DepartmentsBI.GetDepartments();

            ViewData["DepartmentName"] = General.DataTableToSelectList(dtGetDepartment, "DepartmentId", "DepartmentName", "0", TopEmptyItem: new SelectListItem {
                Value = "0", Text = ""
            });

            DataTable dtGetCustodian = EmployeesBI.GetEmployees();

            ViewData["CustodianName"] = General.DataTableToSelectList(dtGetCustodian, "EmployeeId", "FirstName", "0", TopEmptyItem: new SelectListItem {
                Value = "0", Text = ""
            });


            DataTable dtGetAssetConditions = General.GetAssetConditions();

            ViewData["AssetConditions"] = General.DataTableToSelectList(dtGetAssetConditions, "Value", "Text", "0", TopEmptyItem: new SelectListItem {
                Value = "0", Text = ""
            });

            DataTable dtGetAssetStatus = General.GetAssetStatus();

            ViewData["AssetStatuses"] = General.DataTableToSelectList(dtGetAssetStatus, "Value", "Text", "0", TopEmptyItem: new SelectListItem {
                Value = "0", Text = ""
            });

            ViewBag.PreloadDate = DateTime.Now.ToString("dd MMMM yyyy");

            AssetRegister eAssetRegister = new AssetRegister();

            eAssetRegister.dtAssetRegister = AssetRegisterBI.GetAssetRegister();
            return(View(eAssetRegister));
        }
        public ActionResult CreateAssetRegister()
        {
            AssetRegister eAssetRegister = new AssetRegister();
            DataTable     dtGetAssetName = AssetDefinitionBI.GetAssetDefinition();

            ViewData["AssetName"] = General.DataTableToSelectList(dtGetAssetName, "AssetDefinitionId", "AssetName", "0", TopEmptyItem: new SelectListItem {
                Value = "0", Text = ""
            });

            DataTable dtGetSupplier = SuppliersBI.GetSuppliers();

            ViewData["SupplierName"] = General.DataTableToSelectList(dtGetSupplier, "SupplierId", "SupplierFullName", "0", TopEmptyItem: new SelectListItem {
                Value = "0", Text = ""
            });

            DataTable dtGetLocation = LocationBI.GetLocation();

            ViewData["LocationName"] = General.DataTableToSelectList(dtGetLocation, "LocationId", "LocationName", "0", TopEmptyItem: new SelectListItem {
                Value = "0", Text = ""
            });

            DataTable dtGetDepartment = DepartmentsBI.GetDepartments();

            ViewData["DepartmentName"] = General.DataTableToSelectList(dtGetDepartment, "DepartmentId", "DepartmentName", "0", TopEmptyItem: new SelectListItem {
                Value = "0", Text = ""
            });

            DataTable dtGetCustodian = EmployeesBI.GetEmployees();

            ViewData["CustodianName"] = General.DataTableToSelectList(dtGetCustodian, "EmployeeId", "FirstName", "0", TopEmptyItem: new SelectListItem {
                Value = "0", Text = ""
            });


            DataTable dtGetAssetConditions = General.GetAssetConditions();

            ViewData["AssetConditions"] = General.DataTableToSelectList(dtGetAssetConditions, "Value", "Text", "0", TopEmptyItem: new SelectListItem {
                Value = "0", Text = ""
            });

            DataTable dtGetAssetStatus = General.GetAssetStatus();

            ViewData["AssetStatuses"] = General.DataTableToSelectList(dtGetAssetStatus, "Value", "Text", "0", TopEmptyItem: new SelectListItem {
                Value = "0", Text = ""
            });

            ViewBag.PreloadDate = DateTime.Now.ToString("dd MMMM yyyy");
            return(View(eAssetRegister));
        }
Beispiel #3
0
        public ActionResult IndexEmployee()
        {
            ViewBag.AllowAdd    = this.HasPermission(ControllerName.Setups + "-CreateEmployee");
            ViewBag.AllowEdit   = this.HasPermission(ControllerName.Setups + "-EditEmployee");
            ViewBag.AllowDelete = this.HasPermission(ControllerName.Setups + "-DeleteEmployee");

            DataTable dtGender = General.GetGender();

            ViewData["Gender"] = General.DataTableToSelectList(dtGender, "Value", "Text", "0", TopEmptyItem: new SelectListItem {
                Value = "0", Text = ""
            });


            Employees eEmployees = new Employees();

            eEmployees.dtEmployee = EmployeesBI.GetEmployees();
            return(View(eEmployees));
        }
        public ActionResult EditAssetRegister(AssetRegister eAssetRegister)
        {
            if (ModelState.IsValid)
            {
                DataTable dtGetAssetName = AssetDefinitionBI.GetAssetDefinition();
                ViewData["AssetName"] = General.DataTableToSelectList(dtGetAssetName, "AssetDefinitionId", "AssetName", "0", TopEmptyItem: new SelectListItem {
                    Value = "0", Text = ""
                });

                DataTable dtGetSupplier = SuppliersBI.GetSuppliers();
                ViewData["SupplierName"] = General.DataTableToSelectList(dtGetSupplier, "SupplierId", "SupplierFullName", "0", TopEmptyItem: new SelectListItem {
                    Value = "0", Text = ""
                });

                DataTable dtGetLocation = LocationBI.GetLocation();
                ViewData["LocationName"] = General.DataTableToSelectList(dtGetLocation, "LocationId", "LocationName", "0", TopEmptyItem: new SelectListItem {
                    Value = "0", Text = ""
                });

                DataTable dtGetDepartment = DepartmentsBI.GetDepartments();
                ViewData["DepartmentName"] = General.DataTableToSelectList(dtGetDepartment, "DepartmentId", "DepartmentName", "0", TopEmptyItem: new SelectListItem {
                    Value = "0", Text = ""
                });

                DataTable dtGetCustodian = EmployeesBI.GetEmployees();
                ViewData["CustodianName"] = General.DataTableToSelectList(dtGetCustodian, "EmployeeId", "FirstName", "0", TopEmptyItem: new SelectListItem {
                    Value = "0", Text = ""
                });

                DataTable dtGetAssetConditions = General.GetAssetConditions();
                ViewData["AssetConditions"] = General.DataTableToSelectList(dtGetAssetConditions, "Value", "Text", "0", TopEmptyItem: new SelectListItem {
                    Value = "0", Text = ""
                });

                DataTable dtGetAssetStatus = General.GetAssetStatus();
                ViewData["AssetStatuses"] = General.DataTableToSelectList(dtGetAssetStatus, "Value", "Text", "0", TopEmptyItem: new SelectListItem {
                    Value = "0", Text = ""
                });

                ViewBag.PurchaseDate = eAssetRegister.PurchaseDate.ToString("dd/MMM/yyyy");
                if (eAssetRegister.WarrantyExpiry != null)
                {
                    ViewBag.WarantyExpiry = Convert.ToDateTime(eAssetRegister.WarrantyExpiry).ToString("dd/MMM/yyyy");
                }
                if (eAssetRegister.ImagePath != null)
                {
                    ViewBag.ImagePath = eAssetRegister.ImagePath;
                }
                try
                {
                    HttpPostedFileBase file = Request.Files["ImageFile"];
                    if (file.FileName != "")
                    {
                        Random rmd       = new Random();
                        string FileName  = Path.GetFileNameWithoutExtension(file.FileName);
                        string Extension = Path.GetExtension(eAssetRegister.ImageFile.FileName);
                        if (Extension == ".jpg" || Extension == ".png")
                        {
                            FileName = FileName + rmd.Next(100) + Extension;
                            eAssetRegister.ImagePath = "~/images/" + FileName;

                            AssetRegister eNewAssetRegister = new AssetRegister();
                            eNewAssetRegister.AssetRegisterId = eAssetRegister.AssetRegisterId;
                            AssetRegisterBI.LoadAssetRegister(ref eNewAssetRegister);
                            string filepath = eNewAssetRegister.ImagePath;
                            //Deleting the old photo
                            if (filepath != "")
                            {
                                filepath = Server.MapPath(filepath);
                                if (System.IO.File.Exists(filepath))
                                {
                                    System.IO.File.Delete(filepath);
                                }
                            }
                            //Saving the updated image
                            FileName = Path.Combine(Server.MapPath("/images/"), FileName);
                            file.SaveAs(FileName);
                        }
                        else
                        {
                            ModelState.AddModelError("Success", "Unrequired format. Only .jpg and .png images are permitted");
                            ViewBag.ReturnMsg = "Failed";
                            return(View(eAssetRegister));
                        }
                    }
                    else
                    {
                        AssetRegister eNewAssetRegister = new AssetRegister();
                        eNewAssetRegister.AssetRegisterId = eAssetRegister.AssetRegisterId;
                        AssetRegisterBI.LoadAssetRegister(ref eNewAssetRegister);
                        string filepath = eNewAssetRegister.ImagePath;
                        eAssetRegister.ImagePath = filepath;
                    }
                    FASM_Enums.InfoMessages Results = AssetRegisterBI.SaveAssetRegister(ref eAssetRegister);
                    switch (Results)
                    {
                    case FASM_Enums.InfoMessages.Success:
                        ModelState.AddModelError("Success", FASM_Msg.Updated);
                        ViewBag.ReturnMsg = "Success";
                        break;

                    case FASM_Enums.InfoMessages.AlreadyExist:
                        ModelState.AddModelError("Success", "Sorry! the Asset Code already exist");
                        ViewBag.ReturnMsg = "Failed";
                        break;
                    }
                }
                catch (Exception ex)
                {
                    ModelState.AddModelError("", ex.Message);
                }
            }
            return(View(eAssetRegister));
        }
        public ActionResult EditAssetRegister()
        {
            AssetRegister eAssetRegister = new AssetRegister();

            DataTable dtGetAssetName = AssetDefinitionBI.GetAssetDefinition();

            ViewData["AssetName"] = General.DataTableToSelectList(dtGetAssetName, "AssetDefinitionId", "AssetName", "0", TopEmptyItem: new SelectListItem {
                Value = "0", Text = ""
            });

            DataTable dtGetSupplier = SuppliersBI.GetSuppliers();

            ViewData["SupplierName"] = General.DataTableToSelectList(dtGetSupplier, "SupplierId", "SupplierFullName", "0", TopEmptyItem: new SelectListItem {
                Value = "0", Text = ""
            });

            DataTable dtGetLocation = LocationBI.GetLocation();

            ViewData["LocationName"] = General.DataTableToSelectList(dtGetLocation, "LocationId", "LocationName", "0", TopEmptyItem: new SelectListItem {
                Value = "0", Text = ""
            });

            DataTable dtGetDepartment = DepartmentsBI.GetDepartments();

            ViewData["DepartmentName"] = General.DataTableToSelectList(dtGetDepartment, "DepartmentId", "DepartmentName", "0", TopEmptyItem: new SelectListItem {
                Value = "0", Text = ""
            });

            DataTable dtGetCustodian = EmployeesBI.GetEmployees();

            ViewData["CustodianName"] = General.DataTableToSelectList(dtGetCustodian, "EmployeeId", "FirstName", "0", TopEmptyItem: new SelectListItem {
                Value = "0", Text = ""
            });


            DataTable dtGetAssetConditions = General.GetAssetConditions();

            ViewData["AssetConditions"] = General.DataTableToSelectList(dtGetAssetConditions, "Value", "Text", "0", TopEmptyItem: new SelectListItem {
                Value = "0", Text = ""
            });

            DataTable dtGetAssetStatus = General.GetAssetStatus();

            ViewData["AssetStatuses"] = General.DataTableToSelectList(dtGetAssetStatus, "Value", "Text", "0", TopEmptyItem: new SelectListItem {
                Value = "0", Text = ""
            });

            try
            {
                string IdVal = Url.RequestContext.RouteData.Values["Id"].ToString();
                if (General.IsNumeric(IdVal))
                {
                    eAssetRegister.AssetRegisterId = int.Parse(IdVal);
                }

                if (eAssetRegister.AssetRegisterId > 0)
                {
                    AssetRegisterBI.LoadAssetRegister(ref eAssetRegister);
                    ViewBag.PurchaseDate = eAssetRegister.PurchaseDate.ToString("dd/MMM/yyyy");
                    if (eAssetRegister.WarrantyExpiry != null)
                    {
                        ViewBag.WarantyExpiry = Convert.ToDateTime(eAssetRegister.WarrantyExpiry).ToString("dd/MMM/yyyy");
                    }
                    if (eAssetRegister.ImagePath != null)
                    {
                        ViewBag.ImagePath = eAssetRegister.ImagePath;
                    }
                }
                if (eAssetRegister.AssetRegisterId == 0)
                {
                    return(RedirectToAction("IndexAssetIdentity", ControllerName.AssetManagement));
                }
            }
            catch (Exception ex)
            {
                ModelState.AddModelError("", ex.Message);
            }
            return(View(eAssetRegister));
        }
        public ActionResult CreateAssetRegister(AssetRegister eAssetRegister)
        {
            DataTable dtGetAssetName = AssetDefinitionBI.GetAssetDefinition();

            ViewData["AssetName"] = General.DataTableToSelectList(dtGetAssetName, "AssetDefinitionId", "AssetName", "0", TopEmptyItem: new SelectListItem {
                Value = "0", Text = ""
            });

            DataTable dtGetSupplier = SuppliersBI.GetSuppliers();

            ViewData["SupplierName"] = General.DataTableToSelectList(dtGetSupplier, "SupplierId", "SupplierFullName", "0", TopEmptyItem: new SelectListItem {
                Value = "0", Text = ""
            });

            DataTable dtGetLocation = LocationBI.GetLocation();

            ViewData["LocationName"] = General.DataTableToSelectList(dtGetLocation, "LocationId", "LocationName", "0", TopEmptyItem: new SelectListItem {
                Value = "0", Text = ""
            });

            DataTable dtGetDepartment = DepartmentsBI.GetDepartments();

            ViewData["DepartmentName"] = General.DataTableToSelectList(dtGetDepartment, "DepartmentId", "DepartmentName", "0", TopEmptyItem: new SelectListItem {
                Value = "0", Text = ""
            });

            DataTable dtGetCustodian = EmployeesBI.GetEmployees();

            ViewData["CustodianName"] = General.DataTableToSelectList(dtGetCustodian, "EmployeeId", "FirstName", "0", TopEmptyItem: new SelectListItem {
                Value = "0", Text = ""
            });

            DataTable dtGetAssetConditions = General.GetAssetConditions();

            ViewData["AssetConditions"] = General.DataTableToSelectList(dtGetAssetConditions, "Value", "Text", "0", TopEmptyItem: new SelectListItem {
                Value = "0", Text = ""
            });

            DataTable dtGetAssetStatus = General.GetAssetStatus();

            ViewData["AssetStatuses"] = General.DataTableToSelectList(dtGetAssetStatus, "Value", "Text", "0", TopEmptyItem: new SelectListItem {
                Value = "0", Text = ""
            });

            ViewBag.PreloadDate = DateTime.Now.ToString("dd MMMM yyyy");

            HttpPostedFileBase file = Request.Files["ImageFile"];

            if (file.FileName != "")
            {
                Random rmd       = new Random();
                string FileName  = Path.GetFileNameWithoutExtension(file.FileName);
                string Extension = Path.GetExtension(eAssetRegister.ImageFile.FileName);
                if (Extension == ".jpg" || Extension == ".png")
                {
                    FileName = FileName + rmd.Next(100) + Extension;
                    eAssetRegister.ImagePath = "~/images/" + FileName;
                    FileName = Path.Combine(Server.MapPath("/images/"), FileName);
                    file.SaveAs(FileName);
                }
                else
                {
                    ModelState.AddModelError("Success", "Unrequired format. Only .jpg and .png images are permitted");
                    ViewBag.ReturnMsg = "Failed";
                    return(View(eAssetRegister));
                }
            }
            if (ModelState.IsValid)
            {
                try
                {
                    FASM_Enums.InfoMessages SaveResult = AssetRegisterBI.SaveAssetRegister(ref eAssetRegister);
                    switch (SaveResult)
                    {
                    case FASM_Enums.InfoMessages.Success:
                        ModelState.AddModelError("Success", FASM_Msg.SuccessfulSaved);
                        ViewBag.ReturnMsg = "Success";
                        break;

                    case FASM_Enums.InfoMessages.AlreadyExist:
                        ModelState.AddModelError("Success", "Asset Code already exist!");
                        ViewBag.ReturnMsg = "Failed";
                        break;
                    }
                }
                catch (Exception ex)
                {
                    ModelState.AddModelError("", ex.Message);
                }
            }
            return(View(eAssetRegister));
        }