Example #1
0
        public IActionResult Report(int id)
        {
            if (HttpContext.Session.GetString("LoginID") == null)
            {
                return(RedirectToAction("Login", "Users"));
            }
            if (id == 0)
            {
                return(RedirectToAction("ViewReports"));
            }

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

            if (HttpContext.Session.GetString("AdminValidity") == "Admin" || HttpContext.Session.GetString("AdminValidity") == "Super Admin" || context.getServiceReport(id).ReportFrom == context.GetUser(Convert.ToInt32(HttpContext.Session.GetString("LoginID"))).FirstName + context.GetUser(Convert.ToInt32(HttpContext.Session.GetString("LoginID"))).LastName)
            {
                ViewData["allowdelete"] = "weee";
            }
            if ((HttpContext.Session.GetString("AdminValidity") == "Admin" || HttpContext.Session.GetString("AdminValidity") == "Super Admin"))
            {
                ViewData["rights"] = "Admin";
            }


            ServiceReport model = context.getServiceReport(id);

            if (model.SerialNumber == 0)
            {
                return(RedirectToAction("ViewReports"));
            }
            return(View(model));
        }
Example #2
0
        public IActionResult AddBilling(ServiceReport model)
        {
            if (HttpContext.Session.GetString("LoginID") == null)
            {
                return(RedirectToAction("Login", "Users"));
            }
            if (ModelState.IsValid)
            {
                if (model.Labour < 0 || model.Others < 0 || model.Parts < 0 || model.Transport < 0)
                {
                    ModelState.AddModelError("", "Costs cannot be negative");
                    return(View(model));
                }
                if (model.InvoiceNo < 0)
                {
                    ModelState.AddModelError("", "Invoice number cannot be negative");
                    return(View(model));
                }


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

                return(RedirectToAction("Report", model.SerialNumber));
            }
            ModelState.AddModelError("", "Error have occured");
            return(View(model));
        }
Example #3
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 }));
        }
Example #4
0
        public IActionResult Company(string name)
        {
            if (HttpContext.Session.GetString("LoginID") == null)
            {
                return(RedirectToAction("Login", "Users"));
            }
            if (name == "")
            {
                return(RedirectToAction("index"));
            }

            CentricsContext context = HttpContext.RequestServices.GetService(typeof(Centrics.Models.CentricsContext)) as CentricsContext;
            ClientAddress   boo     = context.GetClientAddressList(name);

            if (boo.ClientCompany == "" || boo.ClientCompany == null)
            {
                //what happen when company do not have an address yet?
                Debug.WriteLine("This is not good");
                return(RedirectToAction("index"));
            }
            else
            {
                ViewData["CompanyName"] = boo.ClientCompany;
                if (boo.Addresslist != null)
                {
                    Debug.WriteLine("how the fk is this initialize?" + boo.Addresslist.Count());
                    ViewData["AddressList"] = boo.Addresslist;
                }
            }

            TempData["companyname"] = boo.ClientCompany;
            return(View());
        }
Example #5
0
        public IActionResult AddNewReport()
        {
            if (HttpContext.Session.GetString("LoginID") == null)
            {
                return(RedirectToAction("Login", "Users"));
            }


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

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

            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();
            return(View(model));
        }
        public async Task <IActionResult> GiveMe()
        {
            if (HttpContext.Session.GetString("LoginID") == null)
            {
                Debug.WriteLine("f1");
                return(RedirectToAction("Login", "Users"));
            }
            if (!(HttpContext.Session.GetString("AdminValidity") == "Admin" || HttpContext.Session.GetString("AdminValidity") == "Super Admin"))
            {
                Debug.WriteLine("f2");
                return(RedirectToAction("Error", "Admin"));
            }

            OnPostExport();
            Debug.WriteLine("give me");
            CentricsContext context = HttpContext.RequestServices.GetService(typeof(Centrics.Models.CentricsContext)) as CentricsContext;

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

            string sFileName      = @"Centrics Networks.xlsx";
            string sWebRootFolder = _hostingEnvironment.WebRootPath;
            var    memory         = new MemoryStream();

            using (var stream = new FileStream(Path.Combine(sWebRootFolder, sFileName), FileMode.Open))
            {
                await stream.CopyToAsync(memory);
            }
            memory.Position = 0;

            return(File(memory, "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", sFileName));
        }
Example #7
0
        public IActionResult ViewContract()
        {
            if (HttpContext.Session.GetString("LoginID") == null)
            {
                return(RedirectToAction("Login", "Users"));
            }

            CentricsContext context          = HttpContext.RequestServices.GetService(typeof(Centrics.Models.CentricsContext)) as CentricsContext;
            List <Contract> contractlist     = context.getContracts();
            List <Contract> ValidContract    = new List <Contract>();
            List <Contract> ExpiredContract  = new List <Contract>();
            List <Contract> FutureContract   = new List <Contract>();
            List <Contract> FinishedContract = new List <Contract>();
            int             counter          = contractlist.Count();
            int             i = 0;

            while (counter != 0)
            {
                if (contractlist[i].EndValid.CompareTo(DateTime.Today) >= 0 && (contractlist[i].StartValid.CompareTo(DateTime.Today)) <= 0)
                {
                    if (contractlist[i].MSH != 0)
                    {
                        ValidContract.Add(contractlist[i]);
                    }
                    else
                    {
                        FinishedContract.Add(contractlist[i]);
                    }
                }
                else if (contractlist[i].EndValid.CompareTo(DateTime.Today) < 0)
                {
                    ExpiredContract.Add(contractlist[i]);
                }
                else if (contractlist[i].StartValid.CompareTo(DateTime.Today) > 0)
                {
                    FutureContract.Add(contractlist[i]);
                }
                i++;
                counter--;
            }
            if (FinishedContract.Count != 0)
            {
                ViewData["Finished"] = FinishedContract;
            }
            if (ExpiredContract.Count != 0)
            {
                ViewData["Expired"] = ExpiredContract;
            }
            if (ValidContract.Count != 0)
            {
                ViewData["Valid"] = ValidContract;
            }
            if (FutureContract.Count != 0)
            {
                ViewData["Future"] = FutureContract;
            }
            return(View());
        }
Example #8
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));
        }
        public IActionResult AddClient(Client model)
        {
            if (ModelState.IsValid)
            {
                CentricsContext context = HttpContext.RequestServices.GetService(typeof(Centrics.Models.CentricsContext)) as CentricsContext;
                context.AddClient(model);

                return(RedirectToAction("ViewClient", "Client"));
            }
            return(View());
        }
Example #10
0
        public IActionResult AddBilling(int id)
        {
            if (HttpContext.Session.GetString("LoginID") == null)
            {
                return(RedirectToAction("Login", "Users"));
            }
            CentricsContext context = HttpContext.RequestServices.GetService(typeof(Centrics.Models.CentricsContext)) as CentricsContext;

            ServiceReport model = context.getServiceReport(id);

            return(View(model));
        }
Example #11
0
        public IActionResult Index(searcher val)
        {
            if (HttpContext.Session.GetString("LoginID") == null)
            {
                return(RedirectToAction("Login", "Users"));
            }
            CentricsContext context = HttpContext.RequestServices.GetService(typeof(Centrics.Models.CentricsContext)) as CentricsContext;

            ViewData["viewer"] = context.SearchClientAddress(val.searchvalue);

            return(View());
        }
Example #12
0
        public IActionResult Index()
        {
            if (HttpContext.Session.GetString("LoginID") == null)
            {
                return(RedirectToAction("Login", "Users"));
            }
            CentricsContext context = HttpContext.RequestServices.GetService(typeof(Centrics.Models.CentricsContext)) as CentricsContext;

            ViewData["viewer"] = context.getAllClientAddress();
            List <ClientAddress> listca = context.getAllClientAddress();

            return(View());
        }
Example #13
0
        public IActionResult ViewReports()
        {
            if (HttpContext.Session.GetString("LoginID") == null)
            {
                return(RedirectToAction("Login", "Users"));
            }
            CentricsContext context = HttpContext.RequestServices.GetService(typeof(Centrics.Models.CentricsContext)) as CentricsContext;

            ViewData["Pending"]   = context.getPendingReports();
            ViewData["Confirmed"] = context.getConfirmedReports();

            return(View());
        }
Example #14
0
        public IActionResult SRCalculation()
        {
            if (HttpContext.Session.GetString("LoginID") == null)
            {
                return(RedirectToAction("Login", "Users"));
            }
            if (!(HttpContext.Session.GetString("AdminValidity") == "Super Admin"))
            {
                return(RedirectToAction("Login", "Users"));
            }

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

            return(View(model));
        }
Example #15
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"));
        }
Example #17
0
        public IActionResult ChangeAddressInput()
        {
            if (HttpContext.Session.GetString("LoginID") == null)
            {
                return(RedirectToAction("Login", "Users"));
            }

            string name = "";

            if (((TempData.Peek("dataishere") != null).ToString().ToLower()) == "true")
            {
                name = TempData.Peek("dataishere").ToString();
            }

            if (name == "" || name == null)
            {
                return(View());
            }
            CentricsContext context = HttpContext.RequestServices.GetService(typeof(Centrics.Models.CentricsContext)) as CentricsContext;
            ClientAddress   cA      = context.GetClientAddressList(name);
            List <string>   aList   = new List <string>();

            aList = cA.Addresslist;

            if (aList == null || aList.Count() == 0)
            {
            }
            else
            {
                List <SelectListItem> AddressList = new List <SelectListItem>();
                for (int i = 0; i < aList.Count(); i++)
                {
                    AddressList.Add(new SelectListItem {
                        Value = aList[i], Text = aList[i]
                    });
                }
                ViewData["AddressList"] = AddressList;
            }
            Debug.WriteLine(Url.Action("ChangeAddressInput", "ServiceReport"));
            Debug.WriteLine("muahaahahah pelase?");
            return(PartialView("ChangeAddressInput", new ServiceReport()));
        }
Example #18
0
 public IActionResult SRCalculation(SRCalculation values)
 {
     if (HttpContext.Session.GetString("LoginID") == null)
     {
         return(RedirectToAction("Login", "Users"));
     }
     if (!(HttpContext.Session.GetString("AdminValidity") == "Super Admin"))
     {
         return(RedirectToAction("Login", "Users"));
     }
     if (ModelState.IsValid)
     {
         CentricsContext context = HttpContext.RequestServices.GetService(typeof(Centrics.Models.CentricsContext)) as CentricsContext;
         context.UpdateMSHMultiplier(values);
         TempData["PassFail"] = "Successful edit";
         return(View(values));
     }
     TempData["PassFail"] = "Unsucessful edit";
     return(RedirectToAction("SRCalculation"));
 }
Example #19
0
        public IActionResult PrintReport(int id)
        {
            if (HttpContext.Session.GetString("LoginID") == null)
            {
                return(RedirectToAction("Login", "Users"));
            }
            CentricsContext context = HttpContext.RequestServices.GetService(typeof(Centrics.Models.CentricsContext)) as CentricsContext;
            ServiceReport   model   = context.getServiceReport(id);

            if (model.SerialNumber == 0)
            {
                return(RedirectToAction("ViewReports"));
            }
            string[] m = model.JobStatus;

            string jobcombined = "";

            if (model.JobStatus.Length > 1)
            {
                for (int i = 0; i < model.JobStatus.Length; i++)
                {
                    if (model.JobStatus[i] != model.JobStatus.Last())
                    {
                        jobcombined += model.JobStatus[i] + ",";
                    }
                    else
                    {
                        jobcombined += model.JobStatus[i];
                    }
                }
            }
            else if (model.JobStatus.Length == 1)
            {
                jobcombined = model.JobStatus[0];
            }
            model.JobStat = jobcombined;
            HttpContext.JsReportFeature()
            .Recipe(Recipe.PhantomPdf);

            return(View(model));
        }
Example #20
0
        public IActionResult AddContract()
        {
            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;
            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;

            ViewData["Company"] = companynames;
            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;

            return(View());
        }
Example #21
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"));
        }
Example #22
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"));
        }
Example #23
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 }));
        }
Example #24
0
        public ActionResult AddAddress()
        {
            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"));
            }

            string          name    = TempData.Peek("companyname").ToString();
            CentricsContext context = HttpContext.RequestServices.GetService(typeof(Centrics.Models.CentricsContext)) as CentricsContext;
            ClientAddress   cA      = context.GetClientAddressList(name);

            if (cA.Addresslist == null)
            {
                TempData["Message"] = " false";
            }
            else if (cA.Addresslist.Count() > 0 && cA.Addresslist.Count() < 5)
            {
                TempData["Message"] = "false";
            }
            else if (context.GetClientAddressList(name).Addresslist.Count() == 5)
            {
                TempData["Message"] = "true";
                //return RedirectToAction("company", new { name = name });
            }

            ClientAddress Weeeheee = new ClientAddress {
                ClientCompany = name
            };

            return(PartialView("AddAddress", Weeeheee));
        }
Example #25
0
        public IActionResult EditReport(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")));

            ServiceReport model = new ServiceReport();

            //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;
            #endregion
            //pull db
            model = context.getServiceReport(id);
            if (model.SerialNumber == 0)
            {
                return(RedirectToAction("Report"));
            }
            if (!(HttpContext.Session.GetString("AdminValidity") == "Admin" || HttpContext.Session.GetString("AdminValidity") == "Super Admin" || (user.FirstName + user.LastName) == context.getServiceReport(id).ReportFrom))
            {
                return(RedirectToAction("Error", "Admin"));
            }

            return(View(model));
        }
        private void OnPostImport(Importer import)
        {
            IFormFile file        = import.File;
            string    folderName  = "Upload";
            string    webRootPath = _hostingEnvironment.WebRootPath;
            string    newPath     = Path.Combine(webRootPath, folderName);

            StringBuilder sb = new StringBuilder();

            if (!Directory.Exists(newPath))
            {
                Directory.CreateDirectory(newPath);
            }
            if (file.Length > 0)
            {
                string sFileExtension = Path.GetExtension(file.FileName).ToLower();
                ISheet sheet;
                string fullPath = Path.Combine(newPath, file.FileName);
                Debug.WriteLine(file.ToString());
                Debug.WriteLine(fullPath);
                CentricsContext context = HttpContext.RequestServices.GetService(typeof(Centrics.Models.CentricsContext)) as CentricsContext;

                using (var stream = new FileStream(fullPath, FileMode.Create))
                {
                    Debug.WriteLine(stream.ToString());
                    Debug.WriteLine(stream.CanRead);


                    file.CopyTo(stream);
                    stream.Position = 0;
                    if (sFileExtension == ".xls")
                    {
                        HSSFWorkbook hssfwb = new HSSFWorkbook(stream); //This will read the Excel 97-2000 formats
                        sheet = hssfwb.GetSheetAt(0);                   //get first sheet from workbook
                    }
                    else
                    {
                        XSSFWorkbook hssfwb = new XSSFWorkbook(stream); //This will read 2007 Excel format
                        sheet = hssfwb.GetSheetAt(0);                   //get first sheet from workbook
                    }
                    IRow headerRow = sheet.GetRow(0);                   //Get Header Row
                    int  cellCount = headerRow.LastCellNum;
                    //sb.Append("<table class='table'><tr>");
                    // notneeded?
                    for (int j = 0; j < cellCount; j++)
                    {
                        NPOI.SS.UserModel.ICell cell = headerRow.GetCell(j);
                        if (cell == null || string.IsNullOrWhiteSpace(cell.ToString()))
                        {
                            continue;
                        }
                        //sb.Append("<th>" + cell.ToString() + "</th>");
                    }
                    //sb.Append("</tr>");
                    //sb.AppendLine("<tr>");
                    List <ClientAddress> ListCA = context.getAllClientAddress();

                    for (int i = (sheet.FirstRowNum + 1); i <= sheet.LastRowNum; i++) //Read Excel File
                    {
                        IRow row = sheet.GetRow(i);
                        if (row == null)
                        {
                            continue;
                        }
                        if (row.Cells.All(d => d.CellType == CellType.Blank))
                        {
                            continue;
                        }
                        //if (context.GetClientAddressList(row.GetCell(0).ToString()).ClientCompany != "") continue;
                        bool skip = false; // for ignoring
                        //for (int k = 0; k<ListCA.Count; k++)
                        //{
                        //    if (row.GetCell(0).ToString() == ListCA[i].ClientCompany)
                        //    {
                        //        skip = true;
                        //    } else if (row.GetCell(1).ToString() == ListCA[i].CustomerID)
                        //    {
                        //        skip = true;
                        //    }

                        //}
                        //if (skip)
                        //{
                        //    continue;
                        //}
                        ClientAddress cA = new ClientAddress();
                        cA.EmailList     = new List <string>();
                        cA.TitleList     = new List <string>();
                        cA.Addresslist   = new List <string>();
                        cA.ContactList   = new List <string>();
                        cA.ContactNoList = new List <string>();


                        for (int j = row.FirstCellNum; j < cellCount; j++)
                        {
                            if (row.GetCell(j) != null)
                            {
                                //trying to get the value of an empty cell as empty cell is neither 0 nor null nor "".
                                row.CreateCell(200);
                                if (row.GetCell(j).ToString() == row.GetCell(200).ToString())
                                {
                                    //assuming nothing is at 200 if not get fked?
                                    continue;
                                }
                                if (j == 0)
                                {
                                    cA.ClientCompany = row.GetCell(j).ToString();
                                }
                                else if (j == 1)
                                {
                                    cA.CustomerID = row.GetCell(j).ToString();
                                }
                                else if (j == 2)
                                {
                                    string stringer = "";
                                    stringer = row.GetCell(j).ToString();

                                    cA.Addresslist.Add(stringer);
                                }
                                else if (j == 3)
                                {
                                    cA.TitleList.Add(row.GetCell(j).ToString());
                                }
                                else if (j == 4)
                                {
                                    cA.ContactList.Add(row.GetCell(j).ToString());
                                }
                                else if (j == 5)
                                {
                                    cA.ContactNoList.Add(row.GetCell(j).ToString());
                                }
                                else if (j == 6)
                                {
                                    cA.EmailList.Add(row.GetCell(j).ToString());
                                }
                                else if (j == 7)
                                {
                                    cA.TitleList.Add(row.GetCell(j).ToString());
                                }
                                else if (j == 8)
                                {
                                    cA.ContactList.Add(row.GetCell(j).ToString());
                                }
                                else if (j == 9)
                                {
                                    cA.ContactNoList.Add(row.GetCell(j).ToString());
                                }
                                else if (j == 10)
                                {
                                    cA.EmailList.Add(row.GetCell(j).ToString());
                                }
                            }
                        }
                        //sb.AppendLine("</tr>");
                        Debug.WriteLine("i am done" + "1");
                        context.Imported(cA);
                    }
                    //sb.Append("</table>");
                }
            }
            //return this.Content(sb.ToString());
        }
        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.
        }
 public AdminController(CentricsContext context)
 {
     _context = context;
 }
        private const string GoogleAuthKey = "CentricsNetworks123!@#"; //Can be changed

        public UsersController(CentricsContext context)
        {
            _context = context;
        }
Example #30
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));
        }