public ActionResult Edit([Bind(Include = "TenantId,Code,Name,Description,Culture,TimeZone,Created,Status")] EditTenantViewModel tenantViewModel)
        {
            try
            {
                using (var ctx = new SaasDbContext())
                {
                    // Get existing tenant from db
                    var tenant = ctx.Tenants.Where(t => t.TenantId == tenantViewModel.TenantId).FirstOrDefault();
                    tenant.Code        = tenantViewModel.Code;
                    tenant.Name        = tenantViewModel.Name;
                    tenant.Description = tenantViewModel.Description;
                    tenant.Culture     = tenantViewModel.Culture;
                    tenant.TimeZone    = tenantViewModel.TimeZone;
                    tenant.Status      = tenantViewModel.Status;

                    if (ModelState.IsValid)
                    {
                        ctx.Entry(tenant).State = EntityState.Modified;
                        ctx.SaveChanges();
                        return(RedirectToAction("Index"));
                    }
                }
            }

            catch (Exception ex)
            {
                LogService.Info("Tenants not found", ex.Message, ex.InnerException);
            }

            return(View(tenantViewModel));
        }
Exemple #2
0
        public ActionResult Edit([Bind(Include = "Id,UserId,TenantId,Firstname,LastName,Username,Email,PasswordHash,SecurityStamp,MobileNumber,Gender,Birthdate,Created")] EditUserViewModel userviewmodel)
        {
            try
            {
                using (var ctx = new SaasDbContext())
                {
                    // Get existing user from db
                    var user = ctx.Users.Where(u => u.Id == userviewmodel.UserId).FirstOrDefault();

                    user.Firstname    = userviewmodel.Firstname;
                    user.Lastname     = userviewmodel.Lastname;
                    user.Email        = userviewmodel.Email;
                    user.UserName     = userviewmodel.Email;
                    user.Gender       = userviewmodel.Gender;
                    user.MobileNumber = userviewmodel.MobileNumber;

                    //Get the user role from db
                    var userRoleold = ctx.UserRoles.Where(ui => ui.UserId == userviewmodel.UserId).FirstOrDefault();
                    //Remove user role from db
                    ctx.UserRoles.Remove(userRoleold);
                    ctx.SaveChanges();


                    //Create a new user role
                    var modelRole = new LidiaUserRole()
                    {
                        UserId   = userviewmodel.UserId,
                        RoleId   = userviewmodel.Id,
                        TenantId = userviewmodel.TenantId
                    };

                    if (userviewmodel.UserId == CurrentUser.Id || User.IsInRole("SystemAdministrator") || User.IsInRole("TenantAdministrator"))
                    {
                        if (ModelState.IsValid)
                        {
                            //Update the user
                            ctx.Entry(user).State = EntityState.Modified;
                            ctx.UserRoles.Add(modelRole);
                            ctx.SaveChanges();
                            return(RedirectToAction("Index"));
                        }
                        ViewBag.TenantId = new SelectList(ctx.Tenants.ToList(), "TenantId", "Name");
                    }
                    else
                    {
                        return(View("Authorize"));
                    }
                }
            }

            catch (Exception ex)
            {
                LogService.Info("Applications not found", ex.Message, ex.InnerException);
            }

            return(View(userviewmodel));
        }
        public ActionResult Edit([Bind(Include = "Id,TenantId,Code,Domain,Name,Culture,TimeZone,Updated,Created,Status")] EditApplicationViewModel applicationViewModel)
        {
            try
            {
                using (var ctx = new SaasDbContext())
                {
                    if (applicationViewModel.TenantId == CurrentTenant.TenantId || User.IsInRole("SystemAdministrator"))
                    {
                        //Get existing application from db
                        var application = ctx.Applications.Where(a => a.Id == applicationViewModel.Id).FirstOrDefault();

                        application.Name     = applicationViewModel.Name;
                        application.Code     = applicationViewModel.Code;
                        application.Domain   = applicationViewModel.Domain;
                        application.Culture  = applicationViewModel.Culture;
                        application.TimeZone = applicationViewModel.TimeZone;
                        application.Status   = applicationViewModel.Status;

                        if (ModelState.IsValid)
                        {
                            // Update application
                            ctx.Entry(application).State = EntityState.Modified;
                            ctx.SaveChanges();
                            return(RedirectToAction("Index"));
                        }
                        ViewBag.TenantId = new SelectList(ctx.Tenants.ToList(), "TenantId", "Name");
                    }
                    else
                    {
                        return(View("Authorize"));
                    }
                }
            }

            catch (Exception ex)
            {
                LogService.Info("Applications not found", ex.Message, ex.InnerException);
            }

            return(View(applicationViewModel));
        }