Beispiel #1
0
        public ActionResult UpdateToken(LoginViewModel loginViewModel)
        {
            try
            {
                UserCompanyViewModel userCompanyViewModel = new UserCompanyViewModel();
                userCompanyViewModel = Session["userCompanyViewModel"] as UserCompanyViewModel;

                loginViewModel.Token  = loginViewModel.Token ?? "token not availibe";
                loginViewModel.Device = "web";
                // loginViewModel.DeviceId = System.Net.Dns.GetHostName().ToString();
                //loginViewModel.DeviceId = System.Web.HttpContext.Current.Server.MachineName;
                //loginViewModel.DeviceId = loginViewModel.DeviceId = Request.UserHostAddress;
                //loginViewModel.DeviceId = loginViewModel.DeviceId = Request.UserHostAddress;
                loginViewModel.DeviceId  = loginViewModel.Token.Substring(0, 10);
                loginViewModel.CompanyId = Convert.ToInt32(Session["CompanyId"]);
                loginViewModel.Authority = userCompanyViewModel.Authority;
                loginViewModel.UserName  = userCompanyViewModel.UserName;

                Session["Token"] = loginViewModel.Token.ToString();

                var result = webServices.Post(loginViewModel, "User/UpdateToken", false);
                return(Json("Success", JsonRequestBehavior.AllowGet));
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        public ActionResult Registration(UserViewModel userViewModel)
        {
            try
            {
                var result = webServices.Post(userViewModel, "User/Register", false);

                if (result.StatusCode == System.Net.HttpStatusCode.Accepted)
                {
                    userCompanyViewModel = (new JavaScriptSerializer()).Deserialize <UserCompanyViewModel>(result.Data.ToString());

                    if (userCompanyViewModel.CompanyId > 0)
                    {
                        return(RedirectToAction("Index", "Home"));
                    }
                    else
                    {
                        return(RedirectToAction("Create", "Company"));
                    }
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }

            return(View());
        }
Beispiel #3
0
        public JsonResult AddUserCompany(UserCompanyViewModel model)
        {
            var result = new { Success = "true", Message = "Success" };

            if (ModelState.IsValid)
            {
                var newCompany = Mapper.Map <UserCompany>(model);

                try
                {
                    newCompany.CreatedDate = DateTime.Now;
                    newCompany.UpdatedDate = newCompany.CreatedDate;

                    newCompany.Address.AddressType = _addressService.GetAddressTypeByName(Enumerations.AddressType.Zameldowania.ToString());
                    newCompany.ApplicationUserID   = User.Identity.GetUserId();

                    _userCompanyService.Create(newCompany);
                }
                catch (Exception e)
                {
                    logger.Error(e, e.Message);
                    result = new { Success = "false", Message = WebResources.ErrorMessage };
                }

                return(Json(result, JsonRequestBehavior.AllowGet));
            }
            else
            {
                var error = ModelState.Values.SelectMany(v => v.Errors).FirstOrDefault().ErrorMessage;

                result = new { Success = "false", Message = error };

                return(Json(result, JsonRequestBehavior.AllowGet));
            }
        }
Beispiel #4
0
        public static void CreateUser(UserCompanyViewModel user)
        {
            using (SqlConnection conn = new SqlConnection(_connectionString))
            {
                SqlCommand cmd = new SqlCommand($@"INSERT INTO Users (first_name, last_name, username, company_id) VALUES ('{user.FirstName}','{user.LastName}','{user.Username}',{user.CompanyId})", conn);

                conn.Open();

                cmd.ExecuteNonQuery();
            }
        }
Beispiel #5
0
        public static void UpdateUser(UserCompanyViewModel user)
        {
            using (SqlConnection conn = new SqlConnection(_connectionString))
            {
                SqlCommand cmd = new SqlCommand($@"UPDATE Users SET first_name = '{user.FirstName}', last_name = '{user.LastName}', username = '******', company_id = {user.CompanyId} WHERE id = {user.UserId}", conn);

                conn.Open();

                cmd.ExecuteNonQuery();
            }
        }
Beispiel #6
0
        public async Task <IActionResult> AddUserCompany(UserCompanyViewModel viewModel)
        {
            var user = await _userManager.FindByEmailAsync(viewModel.CollaboratorEmail);

            var userCompany = new UserCompany()
            {
                CompanyId = viewModel.CompanyId,
                UserId    = user.Id
            };
            await _companyService.Save(userCompany);

            return(LocalRedirect(Url.Action("Edit", new { id = viewModel.CompanyId })));
        }
Beispiel #7
0
        public ActionResult Login(LoginViewModel loginViewModel)
        {
            try
            {
                loginViewModel.Token  = loginViewModel.Token ?? "token not availibe";
                loginViewModel.Device = "web";
                //loginViewModel.DeviceId = System.Environment.GetEnvironmentVariable("COMPUTERNAME").ToString();
                //loginViewModel.DeviceId = System.Environment.MachineName.ToString();
                // loginViewModel.DeviceId = System.Web.HttpContext.Current.Server.MachineName;
                //loginViewModel.DeviceId = Request.UserHostAddress;
                loginViewModel.DeviceId = loginViewModel.Token.Substring(0, 10);
                Session["Token"]        = loginViewModel.Token;
                if (ModelState.IsValid)
                {
                    var result = webServices.Post(loginViewModel, "User/Login", false);

                    if (result.StatusCode == System.Net.HttpStatusCode.Accepted)
                    {
                        userCompanyViewModel = (new JavaScriptSerializer()).Deserialize <UserCompanyViewModel>(result.Data.ToString());

                        if (userCompanyViewModel != null)
                        {
                            Session["userCompanyViewModel"] = userCompanyViewModel;
                            Session["CompanyId"]            = userCompanyViewModel.CompanyId;
                            Session["UserId"] = userCompanyViewModel.UserId;
                        }

                        if (userCompanyViewModel.Authority == "CustomerAdmin")
                        {
                            return(RedirectToAction("Index", "Home"));
                        }
                        else if (userCompanyViewModel.Authority == "Admin")
                        {
                            return(RedirectToAction("AdminHome", "Home"));
                        }
                    }

                    ModelState.AddModelError("UserName", "Username or Password Incorrect");
                    return(View(loginViewModel));
                }
                else
                {
                    return(View(loginViewModel));
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Beispiel #8
0
        public ActionResult Edit(int id)
        {
            User user = DataAccess.GetAllUsers().FirstOrDefault(x => x.Id == id);

            UserCompanyViewModel vm = new UserCompanyViewModel();

            vm.UserId    = user.Id;
            vm.FirstName = user.FirstName;
            vm.LastName  = user.LastName;
            vm.Username  = user.Username;
            vm.CompanyId = user.Company.Id;

            return(View(vm));
        }
Beispiel #9
0
        // GET: Users/Details/5
        public async Task <IActionResult> Details(int?id)
        {
            if (!IsLoggedIn())
            {
                return(RedirectToAction("Index", "Account"));
            }
            ViewBag.Admin = User.Claims.ToList()[2].Value;
            if (id == null)
            {
                return(NotFound());
            }

            var user = await _context.Users.FromSql(@"
        SELECT [id]
      ,COALESCE([company_id], 0) company_id
      ,[fname]
      ,[lname]
      ,[address1]
      ,[address2]
      ,[city]
      ,[state]
      ,[zip]
      ,[country]
      ,[phone]
      ,[email]
      ,[password]
      ,COALESCE([is_admin], 'false') is_admin
      ,[gender]
      ,[race]
      ,[role]
      ,[company_length]
      ,[role_length]
FROM [user] 
where deleted_on is null and id={0}", id).FirstOrDefaultAsync <User>();

            if (user == null)
            {
                return(NotFound());
            }
            var company = await _context.Companies.FirstOrDefaultAsync(m => m.Id == user.Company_id);

            UserCompanyViewModel uc = new UserCompanyViewModel();

            uc.user    = user;
            uc.company = company;

            return(View(uc));
        }
Beispiel #10
0
        public ActionResult Login(LoginViewModel loginViewModel)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    var result = webServices.Post(loginViewModel, "User/Login", false);

                    if (result.StatusCode == System.Net.HttpStatusCode.Accepted)
                    {
                        userCompanyViewModel = (new JavaScriptSerializer()).Deserialize <UserCompanyViewModel>(result.Data.ToString());

                        if (userCompanyViewModel != null)
                        {
                            Session["userCompanyViewModel"] = userCompanyViewModel;
                            Session["CompanyId"]            = userCompanyViewModel.CompanyId;
                            Session["UserId"] = userCompanyViewModel.UserId;
                        }

                        if (userCompanyViewModel.Authority == "CustomerAdmin")
                        {
                            return(RedirectToAction("Index", "Home"));
                        }
                        else if (userCompanyViewModel.Authority == "Admin")
                        {
                            return(RedirectToAction("AdminHome", "Home"));
                        }
                    }

                    ModelState.AddModelError("UserName", "Username or Password Incorrect");
                    return(View(loginViewModel));
                }
                else
                {
                    return(View(loginViewModel));
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Beispiel #11
0
        public ActionResult Registration(UserViewModel userViewModel)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    var result = webServices.Post(userViewModel, "User/Register", false);

                    if (result.StatusCode == System.Net.HttpStatusCode.Accepted)
                    {
                        userCompanyViewModel = (new JavaScriptSerializer()).Deserialize <UserCompanyViewModel>(result.Data.ToString());

                        if (userCompanyViewModel.CompanyId > 0)
                        {
                            Session["userCompanyViewModel"] = userCompanyViewModel;

                            return(RedirectToAction("Index", "Home"));
                        }
                        else
                        {
                            return(RedirectToAction("Create", "Company"));
                        }
                    }
                    else if (result.StatusCode == System.Net.HttpStatusCode.OK)
                    {
                        ModelState.AddModelError("UserName", "This email exist, choose another");
                        return(View(userViewModel));
                    }
                }
                else
                {
                    return(View(userViewModel));
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }

            return(View());
        }
Beispiel #12
0
        public ActionResult DisplayCompany(UserCompanyViewModel model)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    var company = _userCompanyService.GetById(model.Id);

                    if (company == null)
                    {
                        ModelState.AddModelError("NotFound", "Nie znaleziono firmy.");
                    }
                    else
                    {
                        company.KRS   = model.KRS;
                        company.NIP   = model.NIP;
                        company.REGON = company.REGON;

                        company.Address.City         = model.UserCompanyAddress.City;
                        company.Address.StreetName   = model.UserCompanyAddress.StreetName;
                        company.Address.StreetNumber = model.UserCompanyAddress.StreetNumber;
                        company.Address.PlaceNumber  = model.UserCompanyAddress.PlaceNumber;
                        company.Address.ZIPCode      = model.UserCompanyAddress.ZIPCode;
                        company.Notes = model.Notes;

                        company.UpdatedDate = DateTime.Now;
                        _userCompanyService.Update(company);
                    }
                }
                catch (Exception e)
                {
                    ModelState.AddModelError("", WebResources.ErrorMessage);
                    logger.Error(e, e.Message);
                }
            }

            return(View(model));
        }
Beispiel #13
0
        public ActionResult Login()
        {
            if (TempData["SuccessPWD"] != null)
            {
                ViewBag.success = TempData["SuccessPWD"];
            }
            if (Session["UserId"] == null && Session["CompanyId"] == null)
            {
                return(View(new LoginViewModel()));
            }
            else
            {
                userCompanyViewModel = Session["userCompanyViewModel"] as UserCompanyViewModel;

                if (userCompanyViewModel.Authority == "Admin")
                {
                    return(RedirectToAction("AdminHome", "Home"));
                }
                else
                {
                    return(RedirectToAction("Index", "Home"));
                }
            }
        }
Beispiel #14
0
        public ActionResult Create(CompnayModel compnayModel, HttpPostedFileBase LogoUrl)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    return(View("Create", compnayModel));
                }
                else
                {
                    using (HttpClient client = new HttpClient())
                    {
                        using (var content = new MultipartFormDataContent())
                        {
                            if (LogoUrl != null)
                            {
                                if (Request.Files.Count > 0)
                                {
                                    var file = LogoUrl;

                                    byte[] fileBytes = new byte[file.InputStream.Length + 1];
                                    file.InputStream.Read(fileBytes, 0, fileBytes.Length);
                                    var fileContent = new ByteArrayContent(fileBytes);
                                    fileContent.Headers.ContentDisposition = new System.Net.Http.Headers.ContentDispositionHeaderValue("LogoUrl")
                                    {
                                        FileName = file.FileName
                                    };
                                    content.Add(fileContent);

                                    content.Add(new StringContent("ClientDocs"), "ClientDocs");
                                }
                            }
                            content.Add(new StringContent(compnayModel.Name ?? "Unknown"), "Name");
                            content.Add(new StringContent("street Data"), "Street");
                            string UserId = Session["UserId"].ToString();
                            content.Add(new StringContent(UserId), "CreatedBy");
                            content.Add(new StringContent(compnayModel.Postcode ?? ""), "Postcode");
                            content.Add(new StringContent(compnayModel.City ?? ""), "City");
                            content.Add(new StringContent(compnayModel.Address ?? ""), "Address");
                            content.Add(new StringContent(compnayModel.State ?? ""), "State");
                            content.Add(new StringContent(compnayModel.Country ?? ""), "Country");
                            content.Add(new StringContent(compnayModel.Cell ?? ""), "Cell");
                            content.Add(new StringContent(compnayModel.Phone ?? ""), "Phone");
                            content.Add(new StringContent(compnayModel.Email ?? ""), "Email");
                            content.Add(new StringContent(compnayModel.Web ?? ""), "Web");
                            content.Add(new StringContent(compnayModel.TRN ?? ""), "TRN");
                            content.Add(new StringContent(compnayModel.Remarks ?? ""), "Remarks");
                            content.Add(new StringContent(compnayModel.OwnerRepresentaive ?? ""), "OwnerRepresentaive");
                            content.Add(new StringContent("true"), "IsActive");

                            //  var result1 = client.PostAsync("http://localhost:64299/api/Company/Add", content).Result;
                            var result = webServices.PostMultiPart(content, "Company/Add", true);
                            if (result.StatusCode == System.Net.HttpStatusCode.Accepted)
                            {
                                var companyViewModel = new CompanyViewModel();
                                companyViewModel = (new JavaScriptSerializer().Deserialize <CompanyViewModel>(result.Data.ToString()));

                                var userCompanyViewModel = new UserCompanyViewModel();
                                userCompanyViewModel = Session["userCompanyViewModel"] as UserCompanyViewModel;

                                UserCompanyViewModel userCompanyViewModel1 = new UserCompanyViewModel
                                {
                                    Authority   = companyViewModel.Authority,
                                    CompanyId   = companyViewModel.Id,
                                    UserId      = companyViewModel.CreatedBy,
                                    FullName    = userCompanyViewModel.FullName,
                                    LogoUrl     = companyViewModel.LogoUrl,
                                    FirstName   = companyViewModel.UserName,
                                    CompanyName = companyViewModel.Name,
                                    UserName    = companyViewModel.UserName,
                                    ImageUrl    = companyViewModel.ImageUrl
                                };

                                Session["userCompanyViewModel"] = userCompanyViewModel1;
                                Session["CompanyId"]            = companyViewModel.Id;
                                Session["UserId"] = companyViewModel.CreatedBy;
                                ViewBag.Message   = "Created";
                                return(RedirectToAction("Index", "Home"));
                            }
                            else
                            {
                                ViewBag.Message = "Failed";
                                return(View(compnayModel));
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Beispiel #15
0
        public ActionResult Index()
        {
            var fuelPricesViewModels = new List <FuelPricesViewModel>();

            try
            {
                int CompanyId = Convert.ToInt32(Session["CompanyId"]);

                if (CompanyId < 1)
                {
                    return(RedirectToAction("Create", "Company"));
                }
                else
                {
                    if (HttpContext.Cache["customerNotificationViewModels"] == null)
                    {
                        var result = webServices.Post(new CustomerNotificationViewModel(), "Advertisement/All");

                        if (result.StatusCode == System.Net.HttpStatusCode.Accepted)
                        {
                            if (result.Data != null)
                            {
                                customerNotificationViewModels = (new JavaScriptSerializer().Deserialize <List <CustomerNotificationViewModel> >(result.Data.ToString()));
                                HttpContext.Cache["customerNotificationViewModels"] = customerNotificationViewModels;
                            }
                        }
                    }
                    else
                    {
                        customerNotificationViewModels = HttpContext.Cache["customerNotificationViewModels"] as List <CustomerNotificationViewModel>;
                    }
                    ViewBag.customerNotificationViewModels = customerNotificationViewModels;

                    SearchViewModel searchViewModel = new SearchViewModel
                    {
                        CompanyId = Convert.ToInt32(Session["CompanyId"])
                    };
                    var resultCustomerStatistics = webServices.Post(searchViewModel, "CustomerOrder/CustomerStatistics");
                    if (resultCustomerStatistics.StatusCode == System.Net.HttpStatusCode.Accepted)
                    {
                        customerOrderStatistics = (new JavaScriptSerializer().Deserialize <CustomerOrderStatistics>(resultCustomerStatistics.Data.ToString()));
                    }
                    ViewBag.customerOrderStatistics = customerOrderStatistics;

                    FuelPricesViewModel fuelPricesViewModel = new FuelPricesViewModel();

                    var resultFuel = webServices.Post(fuelPricesViewModel, "FuelPrices/FuelPricesTopOne");
                    if (resultFuel.StatusCode == System.Net.HttpStatusCode.Accepted)
                    {
                        fuelPricesViewModels = (new JavaScriptSerializer().Deserialize <List <FuelPricesViewModel> >(resultFuel.Data.ToString()));
                    }
                    ViewBag.fuelPricesViewModel  = fuelPricesViewModels[0];
                    ViewBag.fuelPricesViewModels = fuelPricesViewModels;

                    var RequestedData        = customerOrderStatistics.RequestedBySevenDayed;
                    var userCompanyViewModel = new UserCompanyViewModel();
                    Session["RequestedData"] = RequestedData;
                    userCompanyViewModel     = Session["userCompanyViewModel"] as UserCompanyViewModel;

                    if (userCompanyViewModel != null)
                    {
                        TempData["Title"] = userCompanyViewModel.CompanyName ?? "Unknown";
                    }

                    return(View());
                }
            }
            catch (Exception)
            {
                throw;
            }
        }
Beispiel #16
0
 public ActionResult Create(UserCompanyViewModel user)
 {
     DataAccess.CreateUser(user);
     return(RedirectToAction("Index"));
 }