Ejemplo n.º 1
0
        public IActionResult DeleteAddress(string name, string address)
        {
            if (HttpContext.Session.GetString("LoginID") == null)
            {
                return(RedirectToAction("Login", "Users"));
            }
            if (!(HttpContext.Session.GetString("AdminValidity") == "Admin" || HttpContext.Session.GetString("AdminValidity") == "Super Admin"))
            {
                return(RedirectToAction("Error", "Admin"));
            }
            CentricsContext context = HttpContext.RequestServices.GetService(typeof(Centrics.Models.CentricsContext)) as CentricsContext;

            if (!ModelState.IsValid)
            {
                return(RedirectToAction("Company", new { name = name }));
            }
            if (name == "" || name == null || address == "" || address == null)
            {
                return(RedirectToAction("Index"));
            }
            Debug.WriteLine("Kill" + address);
            context.RemoveAddressFromClientList(name, address);
            context.LogAction("Client", "Address (" + address + ") has been removed from client " + name + ".", context.GetUser(Convert.ToInt32(HttpContext.Session.GetString("LoginID"))));
            return(RedirectToAction("Company", new { name = name }));
        }
Ejemplo n.º 2
0
        public IActionResult AddContract(Contract model)
        {
            if (HttpContext.Session.GetString("LoginID") == null)
            {
                return(RedirectToAction("Login", "Users"));
            }
            if (!(HttpContext.Session.GetString("AdminValidity") == "Admin" || HttpContext.Session.GetString("AdminValidity") == "Super Admin"))
            {
                return(RedirectToAction("Error", "Admin"));
            }
            List <SelectListItem> ContractTypeList = new List <SelectListItem>
            {
                new SelectListItem {
                    Value = "Bundled hours with product", Text = "Bundled hours with product"
                },
                new SelectListItem {
                    Value = "Maintenance Contract", Text = "Maintenance Contract"
                }
            };

            ViewData["ContractType"] = ContractTypeList;

            CentricsContext       context         = HttpContext.RequestServices.GetService(typeof(Centrics.Models.CentricsContext)) as CentricsContext;
            List <ClientAddress>  clientAddresses = context.getAllClientAddress();
            List <SelectListItem> companynames    = new List <SelectListItem>();

            for (int i = 0; i < clientAddresses.Count; i++)
            {
                companynames.Add(new SelectListItem {
                    Value = clientAddresses[i].ClientCompany, Text = clientAddresses[i].ClientCompany
                });
            }

            ViewData["Company"] = companynames;

            if (ModelState.IsValid)
            {
                if (!DateComparer(model.StartValid, model.EndValid))
                {
                    ModelState.AddModelError("", "End Date should be set to a date after the start date. ");
                    return(View(model));
                }
                if (!(model.EndValid.CompareTo(DateTime.Today) > 0))
                {
                    ModelState.AddModelError("", "The Contract you are trying to add has an End Date that expired already");
                    return(View(model));
                }

                context.LogAction("Contract", "New " + model.ContractType + " contract has been created for " + model.ClientCompany + " lasting from " + model.StartValid + " to " + model.EndValid + ".", context.GetUser(Convert.ToInt32(HttpContext.Session.GetString("LoginID"))));
                context.AddContract(model);
                return(RedirectToAction("ViewContract"));
            }
            return(View(model));
        }
Ejemplo n.º 3
0
        public IActionResult AddAddress(ClientAddress clientAddress)
        {
            if (HttpContext.Session.GetString("LoginID") == null)
            {
                return(RedirectToAction("Login", "Users"));
            }
            if (!(HttpContext.Session.GetString("AdminValidity") == "Admin" || HttpContext.Session.GetString("AdminValidity") == "Super Admin"))
            {
                return(RedirectToAction("Error", "Admin"));
            }
            CentricsContext context = HttpContext.RequestServices.GetService(typeof(Centrics.Models.CentricsContext)) as CentricsContext;

            context.AddAdresstoClientAddressList(clientAddress);
            context.LogAction("Client", "New address (" + clientAddress.Address + ") has been added to " + clientAddress.ClientCompany + ".", context.GetUser(Convert.ToInt32(HttpContext.Session.GetString("LoginID"))));
            return(RedirectToAction("Company", new { name = clientAddress.ClientCompany }));
        }
        public async Task <IActionResult> Importer(Importer file)
        {
            if (HttpContext.Session.GetString("LoginID") == null)
            {
                return(RedirectToAction("Login", "Users"));
            }
            if (!(HttpContext.Session.GetString("AdminValidity") == "Admin" || HttpContext.Session.GetString("AdminValidity") == "Super Admin"))
            {
                return(RedirectToAction("Error", "Admin"));
            }
            if (!ModelState.IsValid)
            {
                return(View(file));
            }
            CentricsContext context = HttpContext.RequestServices.GetService(typeof(Centrics.Models.CentricsContext)) as CentricsContext;

            Debug.WriteLine("hi " + file.File.ContentType);
            if (file.File.ContentType != "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet")
            {
                ModelState.AddModelError("", "Please specify a .xlsx(Excel) file");
                return(View(file));
            }
            if (file.File == null || file.File.Length == 0)
            {
                ModelState.AddModelError("", "Please specify a file");
                return(View());
            }
            if (file.File.Length > 200000000)
            {
                ModelState.AddModelError("", "Please enter a file smaller than 200mb");
                return(View());
            }
            var path = Path.Combine(
                Directory.GetCurrentDirectory(), "wwwroot", file.File.FileName);


            using (var stream = new FileStream(path, FileMode.Create))
            {
                await file.File.CopyToAsync(stream);
            }


            OnPostImport(file);
            context.LogAction("Import/Export Excel", "User imported an excel file to the application.", context.GetUser(Convert.ToInt32(HttpContext.Session.GetString("LoginID"))));
            return(RedirectToAction("Index", "ClientAddress"));
        }
Ejemplo n.º 5
0
        public IActionResult ReportDelete(int id)
        {
            if (HttpContext.Session.GetString("LoginID") == null)
            {
                return(RedirectToAction("Login", "Users"));
            }
            //checkowner
            CentricsContext context = HttpContext.RequestServices.GetService(typeof(Centrics.Models.CentricsContext)) as CentricsContext;
            //enter user
            User user = context.GetUser(Convert.ToInt32(HttpContext.Session.GetString("LoginID")));

            if (!(HttpContext.Session.GetString("AdminValidity") == "Admin" || HttpContext.Session.GetString("AdminValidity") == "Super Admin" || (user.FirstName + user.LastName) == context.getServiceReport(id).ReportFrom))
            {
                return(RedirectToAction("Login", "Users"));
            }
            if (context.getServiceReport(id).ReportStatus != "Confirmed")
            {
                context.DeleteReport(id);
            }

            context.LogAction("Service Report", "Service Report (SRN: " + id + ") has been deleted.", context.GetUser(Convert.ToInt32(HttpContext.Session.GetString("LoginID"))));
            return(RedirectToAction("ViewReports"));
        }
Ejemplo n.º 6
0
        public IActionResult AddNewCompany(ClientAddress clientAddress)
        {
            if (HttpContext.Session.GetString("LoginID") == null)
            {
                return(RedirectToAction("Login", "Users"));
            }
            if (!(HttpContext.Session.GetString("AdminValidity") == "Admin" || HttpContext.Session.GetString("AdminValidity") == "Super Admin"))
            {
                return(RedirectToAction("Error", "Admin"));
            }
            if (!ModelState.IsValid)
            {
                if (clientAddress.ClientCompany == "")
                {
                    ModelState.AddModelError("", "Please enter a company name");
                }
                else if (clientAddress.Address == "")
                {
                    ModelState.AddModelError("", "Please enter a Address");
                }

                return(View(clientAddress));
            }
            CentricsContext context = HttpContext.RequestServices.GetService(typeof(Centrics.Models.CentricsContext)) as CentricsContext;

            ClientAddress exister = context.GetClientAddressList(clientAddress.ClientCompany);

            if (exister.ClientCompany != "")
            {
                ModelState.AddModelError("", "The company already exists.");
                return(View(clientAddress));
            }

            context.LogAction("Client", clientAddress.ClientCompany + " has been added to the client list with this address (" + clientAddress.Address + ")", context.GetUser(Convert.ToInt32(HttpContext.Session.GetString("LoginID"))));
            context.AddNewCompany(clientAddress);
            return(RedirectToAction("Company", new { name = clientAddress.ClientCompany }));
        }
Ejemplo n.º 7
0
        public IActionResult ReportConfirm(int id)
        {
            if (HttpContext.Session.GetString("LoginID") == null)
            {
                return(RedirectToAction("Login", "Users"));
            }
            CentricsContext context = HttpContext.RequestServices.GetService(typeof(Centrics.Models.CentricsContext)) as CentricsContext;
            User            user    = context.GetUser(Convert.ToInt32(HttpContext.Session.GetString("LoginID")));

            if (!(HttpContext.Session.GetString("AdminValidity") == "Admin" || HttpContext.Session.GetString("AdminValidity") == "Super Admin"))
            {
                return(RedirectToAction("Error", "Admin"));
            }
            ServiceReport meh            = context.getServiceReport(id);
            double        totalmshremain = context.GetRemainingMSHByCompany(meh);

            if (totalmshremain < meh.MSHUsed)
            {
                TempData["error"] = "The company you are trying to confirm currently does not have enough remaining MSH.";

                return(RedirectToAction("Report", new { id }));
            }

            context.LogAction("Service Report", "Service Report (SRN: " + id + ") has been confirmed.", context.GetUser(Convert.ToInt32(HttpContext.Session.GetString("LoginID"))));
            context.ReportConfirm(id);


            ServiceReport remains = context.SubtractMSHUsingSR(context.getServiceReport(id));

            while (remains.MSHUsed != 0)
            {
                remains = context.SubtractMSHUsingSR(remains);
            }

            Debug.WriteLine("hi id = " + id);
            return(RedirectToAction("ViewReports"));
        }
        public async Task <IActionResult> OnPostExport()
        {
            if (HttpContext.Session.GetString("LoginID") == null)
            {
                return(RedirectToAction("Login", "Users"));
            }
            if (!(HttpContext.Session.GetString("AdminValidity") == "Admin" || HttpContext.Session.GetString("AdminValidity") == "Super Admin"))
            {
                return(RedirectToAction("Error", "Admin"));
            }

            Debug.WriteLine("called");
            string               sWebRootFolder = _hostingEnvironment.WebRootPath;
            string               sFileName      = @"Centrics Networks.xlsx";
            string               URL            = string.Format("{0}://{1}/{2}", Request.Scheme, Request.Host, sFileName);
            FileInfo             file           = new FileInfo(Path.Combine(sWebRootFolder, sFileName));
            var                  memory         = new MemoryStream();
            CentricsContext      context        = HttpContext.RequestServices.GetService(typeof(Centrics.Models.CentricsContext)) as CentricsContext;
            List <ClientAddress> ListCA         = context.getAllClientAddress();

            using (var fs = new FileStream(Path.Combine(sWebRootFolder, sFileName), FileMode.Create, FileAccess.Write))
            {
                IWorkbook workbook;
                workbook = new XSSFWorkbook();
                ISheet excelSheet = workbook.CreateSheet("Centrics Network");
                IRow   row        = excelSheet.CreateRow(0);

                row.CreateCell(0).SetCellValue("Company Name");
                row.CreateCell(1).SetCellValue("Customer ID");
                row.CreateCell(2).SetCellValue("Address");
                row.CreateCell(3).SetCellValue("Primary Title");
                row.CreateCell(4).SetCellValue("Primary Contact");
                row.CreateCell(5).SetCellValue("Pri. Contact Number");
                row.CreateCell(6).SetCellValue("Primary Email Address");
                row.CreateCell(7).SetCellValue("Secondary Title");
                row.CreateCell(8).SetCellValue("Secondary Contact");
                row.CreateCell(9).SetCellValue("Sec Contact Number");
                row.CreateCell(10).SetCellValue("Secondary Email Address");

                int counter = 1;
                for (int i = 0; i < ListCA.Count; i++)
                {
                    row = excelSheet.CreateRow(counter);
                    row.CreateCell(0).SetCellValue(ListCA[i].ClientCompany);
                    row.CreateCell(1).SetCellValue(ListCA[i].CustomerID);
                    if (ListCA[i].Addresslist != null)
                    {
                        row.CreateCell(2).SetCellValue(ListCA[i].Addresslist[0]);
                    }
                    else
                    {
                        row.CreateCell(2).SetCellValue("");
                    }
                    row.CreateCell(3).SetCellValue("");
                    if (ListCA[i].ContactList != null)
                    {
                        row.CreateCell(4).SetCellValue(ListCA[i].ContactList[0]);
                    }
                    else
                    {
                        row.CreateCell(4).SetCellValue("");
                    }
                    if (ListCA[i].ContactNoList != null)
                    {
                        row.CreateCell(5).SetCellValue(ListCA[i].ContactNoList[0]);
                    }
                    else
                    {
                        row.CreateCell(5).SetCellValue("");
                    }
                    if (ListCA[i].EmailList != null)
                    {
                        row.CreateCell(6).SetCellValue(ListCA[i].EmailList[0]);
                    }
                    else
                    {
                        row.CreateCell(6).SetCellValue("");
                    }
                    row.CreateCell(7).SetCellValue("");
                    if (ListCA[i].ContactList != null && ListCA[i].ContactList.Count > 1)
                    {
                        row.CreateCell(8).SetCellValue(ListCA[i].ContactList[1]);
                    }
                    else
                    {
                        row.CreateCell(8).SetCellValue("");
                    }
                    if (ListCA[i].ContactNoList != null && ListCA[i].ContactNoList.Count > 1)
                    {
                        row.CreateCell(9).SetCellValue(ListCA[i].ContactList[i]);
                    }
                    else
                    {
                        row.CreateCell(9).SetCellValue("");
                    }
                    if (ListCA[i].EmailList != null && ListCA[i].EmailList.Count > 1)
                    {
                        row.CreateCell(10).SetCellValue(ListCA[i].EmailList[1]);
                    }
                    else
                    {
                        row.CreateCell(10).SetCellValue("");
                    }
                    counter++;
                }

                //original test data to create the excel
                //row.CreateCell(0).SetCellValue("ID");
                //row.CreateCell(1).SetCellValue("Name");
                //row.CreateCell(2).SetCellValue("Age");

                //row = excelSheet.CreateRow(1);
                //row.CreateCell(0).SetCellValue(1);
                //row.CreateCell(1).SetCellValue("Kane Williamson");
                //row.CreateCell(2).SetCellValue(29);

                //row = excelSheet.CreateRow(2);
                //row.CreateCell(0).SetCellValue(2);
                //row.CreateCell(1).SetCellValue("Martin Guptil");
                //row.CreateCell(2).SetCellValue(33);

                //row = excelSheet.CreateRow(3);
                //row.CreateCell(0).SetCellValue(3);
                //row.CreateCell(1).SetCellValue("Colin Munro");
                //row.CreateCell(2).SetCellValue(23);

                excelSheet.CreateFreezePane(1, 0, 1, 0);

                workbook.Write(fs);
            }
            Debug.WriteLine("generate done");
            using (var stream = new FileStream(Path.Combine(sWebRootFolder, sFileName), FileMode.Open))
            {
                await stream.CopyToAsync(memory);
            }
            memory.Position = 0;


            context.LogAction("Import/Export Excel", "User exported an excel file from the application.", context.GetUser(Convert.ToInt32(HttpContext.Session.GetString("LoginID"))));

            return(File(memory, "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", sFileName));
            //auto sizing causes the return to be a blank class/cshtml page when click on excel.
        }
Ejemplo n.º 9
0
 public IActionResult RegisterUser(User model)
 {
     model.UserRole = "User";
     //If user input for registration is valid
     if (ModelState.IsValid)
     {
         //Check whether email is already existing in the database
         Boolean validEmail = _context.CheckExistingEmail(model);
         if (validEmail)
         {
             _context.RegisterUser(model);
             User registeredUser = _context.GetUserByEmail(model.UserEmail);
             _context.LogAction("Registration", "User " + registeredUser.FirstName + " " + registeredUser.LastName + " has successfully registered with " + registeredUser.UserEmail + " as ID " + registeredUser.UserID + ".", registeredUser);
             TempData["Status"] = "Registration successful. Please login here.";
             return(RedirectToAction("Login"));
         }
         else
         {
             ViewBag.Message   = "Email already exists, please enter another email.";
             ViewData["Roles"] = model.Roles;
             return(View());
         }
     }
     ViewData["Roles"] = model.Roles;
     return(View());
 }
Ejemplo n.º 10
0
        public IActionResult EditReport(ServiceReport report)
        {
            if (HttpContext.Session.GetString("LoginID") == null)
            {
                return(RedirectToAction("Login", "Users"));
            }

            List <SelectListItem> PurposeList = new List <SelectListItem>();

            PurposeList.Add(new SelectListItem {
                Value = "Project", Text = "Project"
            });
            PurposeList.Add(new SelectListItem {
                Value = "Installation", Text = "Installation"
            });
            PurposeList.Add(new SelectListItem {
                Value = "M.S.A", Text = "M.S.A"
            });
            PurposeList.Add(new SelectListItem {
                Value = "Chargable", Text = "Chargable"
            });
            PurposeList.Add(new SelectListItem {
                Value = "P.O.C", Text = "P.O.C"
            });
            PurposeList.Add(new SelectListItem {
                Value = "Delivery", Text = "Delivery"
            });
            PurposeList.Add(new SelectListItem {
                Value = "Return", Text = "Return"
            });
            PurposeList.Add(new SelectListItem {
                Value = "Others", Text = "Others"
            });
            ViewData["Purpose"] = PurposeList;

            List <SelectListItem> JobStatusList = new List <SelectListItem>();

            JobStatusList.Add(new SelectListItem {
                Value = "Completed", Text = "Completed"
            });
            JobStatusList.Add(new SelectListItem {
                Value = "Followup Required", Text = "Followup Required"
            });
            JobStatusList.Add(new SelectListItem {
                Value = "Recommendation Requied", Text = "Recommendation Required"
            });
            JobStatusList.Add(new SelectListItem {
                Value = "Escalated to Ext. Support", Text = "Escalated to Ext. Support"
            });
            ViewData["JobStatusList"] = JobStatusList;
            //update database
            CentricsContext context = HttpContext.RequestServices.GetService(typeof(Centrics.Models.CentricsContext)) as CentricsContext;
            User            user    = context.GetUser(Convert.ToInt32(HttpContext.Session.GetString("LoginID")));

            if (!(HttpContext.Session.GetString("AdminValidity") == "Admin" || HttpContext.Session.GetString("AdminValidity") == "Super Admin" || (user.FirstName + user.LastName) == context.getServiceReport(report.SerialNumber).ReportFrom))
            {
                return(RedirectToAction("Login", "Users"));
            }
            if (!ModelState.IsValid)
            {
                return(View(report));
            }

            if (ModelState.IsValid)
            {
                double totalmshremain = context.GetRemainingMSHByCompany(report);
                Debug.WriteLine("Debug from post editreport: Total MSH Remaining : " + totalmshremain);
                double calculatedhours = context.CalculateMSH(report.TimeStart, report.TimeEnd);
                //ModelState.AddModelError("", "The calculated MSH:" + calculatedhours);
                //return View(model);
                if (totalmshremain < calculatedhours)
                {
                    ModelState.AddModelError("", "The company you have selected does not have enough remaining MSH, Please contact your Boss immediately regarding this issue.");
                    return(View(report));
                }


                if (report.TimeStart > DateTime.Now || report.TimeEnd > DateTime.Now)
                {
                    ModelState.AddModelError("", "Please enter a report after the service is rendered");
                    return(View(report));
                }

                if (!(report.TimeStart.CompareTo(report.TimeEnd) <= 0))
                {
                    ModelState.AddModelError("", "your start time should be before your end time");
                    return(View(report));
                }

                context.ReportEdit(report);
                context.LogAction("Service Report", "Service Report (SRN: " + report.SerialNumber + ") has been edited.", context.GetUser(Convert.ToInt32(HttpContext.Session.GetString("LoginID"))));
                return(RedirectToAction("Report", new { id = report.SerialNumber }));
            }

            return(View(report));
        }
Ejemplo n.º 11
0
        public IActionResult AddNewReport(ServiceReport model)
        {
            if (HttpContext.Session.GetString("LoginID") == null)
            {
                return(RedirectToAction("Login", "Users"));
            }


            CentricsContext context = HttpContext.RequestServices.GetService(typeof(Centrics.Models.CentricsContext)) as CentricsContext;

            ViewData["Companies"] = context.GetClientByContract();

            #region prepare for failure codes
            List <SelectListItem> PurposeList = new List <SelectListItem>();
            PurposeList.Add(new SelectListItem {
                Value = "Project", Text = "Project"
            });
            PurposeList.Add(new SelectListItem {
                Value = "Installation", Text = "Installation"
            });
            PurposeList.Add(new SelectListItem {
                Value = "M.S.A", Text = "M.S.A"
            });
            PurposeList.Add(new SelectListItem {
                Value = "Chargable", Text = "Chargable"
            });
            PurposeList.Add(new SelectListItem {
                Value = "P.O.C", Text = "P.O.C"
            });
            PurposeList.Add(new SelectListItem {
                Value = "Delivery", Text = "Delivery"
            });
            PurposeList.Add(new SelectListItem {
                Value = "Return", Text = "Return"
            });
            PurposeList.Add(new SelectListItem {
                Value = "Others", Text = "Others"
            });
            ViewData["Purpose"] = PurposeList;

            List <SelectListItem> JobStatusList = new List <SelectListItem>();
            JobStatusList.Add(new SelectListItem {
                Value = "Completed", Text = "Completed"
            });
            JobStatusList.Add(new SelectListItem {
                Value = "Followup Required", Text = "Followup Required"
            });
            JobStatusList.Add(new SelectListItem {
                Value = "Recommendation Requied", Text = "Recommendation Required"
            });
            JobStatusList.Add(new SelectListItem {
                Value = "Escalated to Ext. Support", Text = "Escalated to Ext. Support"
            });
            ViewData["JobStatusList"] = JobStatusList;

            model.SerialNumber = context.getReportCounts() + 1;
            string name = "";
            if (((TempData.Peek("dataishere") != null).ToString().ToLower()) == "true")
            {
                name = TempData.Peek("dataishere").ToString();
            }

            if (name != "")
            {
                ClientAddress         cA          = context.GetClientAddressList(name);
                List <string>         aList       = cA.Addresslist;
                List <SelectListItem> AddressList = new List <SelectListItem>();
                if (aList != null)
                {
                    for (int i = 0; i < aList.Count(); i++)
                    {
                        AddressList.Add(new SelectListItem {
                            Value = aList[i], Text = aList[i]
                        });
                    }
                }
                ViewData["AddressList"] = AddressList;
            }
            else
            {
                ModelState.AddModelError("", "A error occured. Important");
                return(View(model));
            }
            #endregion
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            if (ModelState.IsValid)
            {
                double totalmshremain  = context.GetRemainingMSHByCompany(model);
                double calculatedhours = context.CalculateMSH(model.TimeStart, model.TimeEnd);
                //for test purpose
                //ModelState.AddModelError("", "The calculated MSH:" + calculatedhours);
                //return View(model);
                if (totalmshremain < calculatedhours)
                {
                    ModelState.AddModelError("", "The company you have selected does not have enough remaining MSH, Please contact your Boss immediately regarding this issue.");
                    return(View(model));
                }
                if (context.CheckExisitingReportID(model.SerialNumber))
                {
                    ModelState.AddModelError("", "Contact Application Developer");
                    return(View(model));
                }

                if (model.TimeStart > DateTime.Now || model.TimeEnd > DateTime.Now)
                {
                    ModelState.AddModelError("", "Please enter a report after the service is rendered");
                    return(View(model));
                }

                if (!(model.TimeStart.CompareTo(model.TimeEnd) <= 0))
                {
                    ModelState.AddModelError("", "your start time should be before your end time");
                    return(View(model));
                }
                User user = context.GetUser(Convert.ToInt32(HttpContext.Session.GetString("LoginID")));
                model.ReportFrom = user.FirstName + user.LastName;
                context.AddServiceReport(model);
                context.LogAction("Service Report", "Service Report (SRN: " + model.SerialNumber + ") created for " + model.ClientCompanyName + " at " + model.ClientAddress + ".", context.GetUser(Convert.ToInt32(HttpContext.Session.GetString("LoginID"))));
                TempData.Remove("dataishere");
                return(RedirectToAction("ViewReports", "ServiceReport"));
            }

            return(View(model));
        }