Exemple #1
0
        public async Task<ActionResult> GetCompanyUsers(CompanyViewModel model)
        {


            model.MyCompanyViewModel = new MyCompanyViewModel();

            var myUser = await UserManager.FindByIdAsync(User.Identity.GetUserId());

            model.MyCompanyViewModel.MyCompany = FujiRepository.GetUserCompany(myUser);

            model.MyCompanyViewModel.CompanyUsers = FujiRepository.GetCompanyUsers(model.MyCompanyViewModel.MyCompany);

            model.MyCompanyViewModel.MyCompany.CompanyNumberOfCameras =
                FujiRepository.GetNumberOfSoldCamerasinCompany(model.MyCompanyViewModel.MyCompany);

            model.MyCompanyViewModel.GlobalRank = FujiRepository.GetGlobalRank(myUser);


            return View(model);
        }
Exemple #2
0
        public async Task<ActionResult> GetCompanies(CompanyViewModel model)
        {
            var LoggedInUser = await UserManager.FindByIdAsync(User.Identity.GetUserId());

            if (!LoggedInUser.Approved)
                return RedirectToAction("Index", "Manage");

            model.GetCompaniesViewModel = new GetCompaniesViewModel();
            model.GetCompaniesViewModel.Companies = new List<Company>();
            model.GetCompaniesViewModel.Companies =
                HttpContext.GetOwinContext().Get<ApplicationDbContext>().Companies.ToList();
            var users = HttpContext.GetOwinContext().Get<ApplicationDbContext>().Users;

            model.GetCompaniesViewModel.Companies.ForEach(
                x =>
                    x.CompanyNumberOfCameras =
                        users.Where(y => y.CompanyId == x.CompanyId).ToList().Sum(user => user.NumberOfCameras));
            model.GetCompaniesViewModel.Companies.ForEach(
                x => x.CompanyNumberOfMembers = users.Where(y => y.CompanyId == x.CompanyId).ToList().Count());


            return View(model);
        }
Exemple #3
0
        public async Task<ActionResult> AddCompany(CompanyViewModel model)
        {

            if (ModelState.IsValid)
            {

                var LoggedInUser = await UserManager.FindByIdAsync(User.Identity.GetUserId());

                if (!LoggedInUser.Approved)
                    return RedirectToAction("Index", "Manage");

                var context = HttpContext.GetOwinContext().Get<ApplicationDbContext>();
                var comp = new Company()
                {
                    CompanyName = model.AddCompanyViewModel.CompanyName,
                    CompanyInfo = model.AddCompanyViewModel.CompanyInfo
                };
                context.Companies.Add(comp);
                context.SaveChanges();
            }


            return RedirectToAction("Index");
        }