예제 #1
0
        public async Task <IActionResult> Create(CreateInstitutionViewModel model)
        {
            if (ModelState.IsValid)
            {
                var manager = await UserManager.FindByIdAsync(model.ManagerId);

                string name = model.Name;


                EInstitution inst = new EInstitution()
                {
                    Name    = name,
                    Manager = manager
                };
                DBContext.Institutions.Add(inst);
                await DBContext.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }
            else
            {
                model.AvailableManagers = await UserManager.GetUsersInRoleAsync("Manager");
            }
            return(View(model));
        }
예제 #2
0
        public IActionResult RegisterInstitution(CreateInstitutionViewModel model)
        {
            Logger.Log(LogLevel.Information, "Accessed Register Institution, UserIsAdmin: {1}", User.IsInRole(sysAdmin));
            if (ModelState.IsValid)
            {
                Institution inst = new Institution
                {
                    Name   = model.InstituteName,
                    Domain = model.InstituteDomain
                };

                List <Institution> res = dbCon.Institution.Where(x => x.Name == inst.Name && x.Domain == inst.Domain).ToList();

                if (res.Count == 0)
                {
                    var added = dbCon.Institution.Add(inst);
                    if (dbCon.SaveChanges() == 1)
                    {
                        Logger.Log(LogLevel.Information, "Register intitution model was Created, UserIsAdmin: {1}", User.IsInRole(sysAdmin));
                        return(RedirectToAction("ListInstitutions", "sysadmin"));
                    }
                    ModelState.AddModelError("", "Could not save entry. Error saving to data base");
                    return(View(model));
                }


                ModelState.AddModelError("", "This institution already exists with this domain");
            }
            Logger.Log(LogLevel.Error, "Register intitution model was not valid, UserIsAdmin: {1}", User.IsInRole(sysAdmin));

            return(View(model));
        }
예제 #3
0
        public async Task <IActionResult> Create()
        {
            CreateInstitutionViewModel model = new CreateInstitutionViewModel()
            {
                AvailableManagers = await UserManager.GetUsersInRoleAsync("Manager"),
                userGrants        = await checkService.getUserGrants(User)
            };

            return(View(model));
        }