Пример #1
0
        public ActionResult Edit(ExerciseViewModel postedModel, string categories)
        {
            if (!ModelState.IsValid)
            {
                return(View(postedModel));
            }

            var exr = RavenSession.Load <Exercise>("exercises/" + postedModel.Id);

            if (!Ownership.Owns(exr, this))
            {
                return(HttpNotFound());
            }


            //if (exr.AccountId != LoggedInUser.AccountId)
            //{
            //    if (!ApplicationAdministrator)
            //    {
            //        return HttpNotFound();
            //    }
            //}

            UpdateModel(exr);

            string[] lines = categories.Split(new string[] { "\r\n", "\n" }, StringSplitOptions.None);
            exr.Categories = new List <string>(lines.Where(x => !string.IsNullOrWhiteSpace(x)));

            exr.Name = exr.Name.Trim();

            RavenSession.SaveChanges();
            HighFive("Exercise edited ok.");

            return(RedirectToAction("List"));
        }
Пример #2
0
        public ActionResult Delete(int protocolId)
        {
            var plan = RavenSession.Load <Protocol>("protocols/" + protocolId);

            if (plan == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.NotFound, "Protocol not found"));
            }

            if (!Ownership.Owns(plan, this))
            {
                return(HttpNotFound());
            }

            if (LoggedInUser.ClinicIds.Contains(plan.ClinicId))
            {
                return(new HttpStatusCodeResult(HttpStatusCode.NotFound, "Protocol not found"));
            }

            RavenSession.Delete(plan);
            RavenSession.SaveChanges();

            HighFive("Protocol deleted successfuly");

            return(RedirectToAction("List"));
        }
Пример #3
0
        public ApiResponse SaveUser(UserPostedModel postedModel)
        {
            if (!ModelState.IsValid)
            {
                return(new ApiResponse("Validation errors occured."));
            }

            var user = RavenSession.Load <User>("users/" + postedModel.Id);

            if (user == null || user.AccountId != Account.Id)
            {
                return(new ApiResponse("User not found"));
            }

            if (!Ownership.Owns(user, this))
            {
                return(new ApiResponse("User not found"));
            }

            user.Name  = postedModel.Name;
            user.Email = postedModel.Email;
            RavenSession.SaveChanges();

            return(new ApiResponse(success: string.Format("User {0} edited", user.Email)));
        }
Пример #4
0
        public ActionResult Delete(int id)
        {
            var user = RavenSession.Load <User>("users/" + id);

            if (user == null)
            {
                WarnUser("User could not be found.");
                return(RedirectToAction("Index"));
            }

            if (!Ownership.Owns(user, this))
            {
                return(HttpNotFound());
            }

            var exercises = RavenSession.Query <Exercise>(typeof(ByOwnableAndName).Name).
                            Where(x => !x.Master && (x.AccountId == user.AccountId)).Take(1024);

            foreach (var exercise in exercises)
            {
                RavenSession.Delete(exercise);
            }

            var account = RavenSession.Load <Account>("accounts/" + user.AccountId);

            RavenSession.Delete(account);
            RavenSession.Delete(user);

            RavenSession.SaveChanges();

            this.HighFive("User deleted.");

            return(RedirectToAction("Index"));
        }
Пример #5
0
        public ApiResponse Disable(int userId)
        {
            var user = RavenSession.Load <User>("users/" + userId);

            if (user == null || user.AccountId != Account.Id)
            {
                return(new ApiResponse("User not found"));
            }

            if (!Ownership.Owns(user, this))
            {
                return(new ApiResponse("User not found"));
            }

            if (user.Status != UserStatus.Disabled)
            {
                user.Status = UserStatus.Active;
            }

            if (user.Status != UserStatus.Active)
            {
                user.Status = UserStatus.Disabled;
            }

            RavenSession.SaveChanges();

            return(new ApiResponse(success: "User status changed"));
        }
Пример #6
0
        public ActionResult EditProtocol(Protocol postedProgram)
        {
            var loadedProtocol = RavenSession.Load <Protocol>("protocols/" + postedProgram.Id);

            if (!Ownership.Owns(loadedProtocol, this))
            {
                return(HttpNotFound());
            }

            UpdateModel(loadedProtocol);

            RavenSession.SaveChanges();

            return(Json(true));
        }
Пример #7
0
        public ActionResult Delete(int id)
        {
            var exr = RavenSession.Load <Exercise>("exercises/" + id);

            if (!Ownership.Owns(exr, this))
            {
                return(HttpNotFound());
            }

            RavenSession.Delete(exr);
            RavenSession.SaveChanges();

            HighFive("Exercise deleted.");

            return(RedirectToAction("List"));
        }
Пример #8
0
        public ActionResult EditProgram(Program postedProgram, bool?resend = false)
        {
            var program = RavenSession.Load <Program>("programs/" + postedProgram.Id);

            if (!Ownership.Owns(program, this))
            {
                return(HttpNotFound());
            }

            UpdateModel(program);

            RavenSession.SaveChanges();

            new ProgramEmailer(this).SendToPatient(program.Id, program.Email, program.ShortUrl);

            return(Json(true));
        }
Пример #9
0
        public ActionResult Edit(int id)
        {
            var exercise = RavenSession.Load <Exercise>("exercises/" + id);

            if (!Ownership.Owns(exercise, this))
            {
                return(HttpNotFound());
            }

            var vm = new ExerciseViewModel();

            Mapper.Map(exercise, vm);

            vm.Categories = string.Join("\r\n", exercise.Categories);


            return(View(vm));
        }
Пример #10
0
        public ActionResult LoadProtocol(int protocolId)
        {
            var program = RavenSession.Query <Protocol>().FirstOrDefault(x => x.Id == protocolId && x.UserId == LoggedInUser.Id);

            if (program == null)
            {
                return(HttpNotFound("Protocol not found"));
            }

            if (!Ownership.Owns(program, this))
            {
                return(HttpNotFound());
            }

            return(View("ProgramBuilder", new ProgramBuilderViewModel()
            {
                Clinic = Clinic, User = LoggedInUser, ExerciseSet = program
            }));
        }
Пример #11
0
        public ActionResult LoadProgram(int programId)
        {
            var program = RavenSession.Load <Program>("programs/" + programId);

            if (program == null)
            {
                return(HttpNotFound("Program not found"));
            }

            if (!Ownership.Owns(program, this))
            {
                return(HttpNotFound());
            }

            return(View("ProgramBuilder", new ProgramBuilderViewModel()
            {
                Clinic = Clinic, User = LoggedInUser, ExerciseSet = program
            }));
        }
Пример #12
0
        public UserViewModel GetUser(int userId)
        {
            var user = RavenSession.Load <User>("users/" + userId);

            if (!Ownership.Owns(user, this))
            {
                throw new HttpResponseException(HttpStatusCode.NotFound);
            }

            var userVm = new UserViewModel()
            {
                Email     = user.Email,
                Id        = user.Id,
                Name      = user.Name,
                Status    = user.Status.ToString(),
                LastLogin = user.LastLogin,
                CreatedOn = user.CreatedOn
            };

            return(userVm);
        }
Пример #13
0
        public ApiResponse ResendInvitation(UserPostedModel postedModel)
        {
            var invitation = RavenSession.Query <UserInvitation>().FirstOrDefault(x => x.ToUserId == postedModel.Id);

            if (invitation == null)
            {
                return(new ApiResponse("Invitation not sent yet or can't be found."));
            }

            var user = RavenSession.Load <User>("users/" + invitation.ToUserId);

            if (user == null)
            {
                return(new ApiResponse("Invited user can't be found"));
            }

            if (!Ownership.Owns(user, this))
            {
                return(new ApiResponse("User not found"));
            }

            SendInvitation(invitation, user);
            return(new ApiResponse(success: "Invitation email resent successfuly"));
        }