Пример #1
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 }));
        }