public ActionResult NewProgram(Program newProgram)
        {
            if (string.IsNullOrWhiteSpace(newProgram.Email))
            {
                return(Json(new { success = false }));
            }

            newProgram.ShortUrl = ShortUrl.Create();
            newProgram.Created  = DateTime.Now;

            Ownership.Assign(newProgram, this);

            if (!LoggedInUser.OnboardingTasks.Contains(OnboardingTask.CreatedProgram.ToString()))
            {
                LoggedInUser.OnboardingTasks.Add(OnboardingTask.CreatedProgram.ToString());
            }

            RavenSession.Store(newProgram);
            RavenSession.SaveChanges();

            new Emailer(this).SendEmail(EmailEnum.SendToPatient, newProgram.Email, newProgram.ShortUrl, newProgram.Id);

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

            return(Json(true));
        }
示例#2
0
        public ActionResult ToggleChallenge(string id, string currentUser, bool single, string boardName, int count)
        {
            if (HttpContext.User.Identity.Name != currentUser)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.Forbidden));
            }

            var board = RavenSession
                        .Query <Board>()
                        .FirstOrDefault(x => x.UserName == currentUser && x.BoardName == boardName);

            if (board == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.NotFound));
            }

            var definition = RavenSession.Load <BoardDefinition>(board.BoardDefinitionId);

            if (definition == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.NotFound));
            }

            var activityName = definition.Cards.FirstOrDefault(x => x.Id == id)?.Text;

            UpdateCompletedCards(single, board, id, count, activityName);
            RavenSession.Store(board);

            return(new HttpStatusCodeResult(HttpStatusCode.OK));
        }
示例#3
0
        public ActionResult Register(RegisterModel model)
        {
            if (ModelState.IsValid)
            {
                // Attempt to register the user
                try
                {
                    var newUser = new User();
                    newUser.SetPassword(model.Password);
                    newUser.UserName = model.UserName;
                    newUser.Email    = model.Email;
                    newUser.Enabled  = true;

                    RavenSession.Store(newUser);

                    RavenSession.SaveChanges();

                    //WebSecurity.CreateUserAndAccount(model.UserName, model.Password);
                    FormsAuthentication.SetAuthCookie(newUser.UserName, true);



                    //WebSecurity.Login(model.UserName, model.Password);
                    return(RedirectToAction("Index", "Home"));
                }
                catch (MembershipCreateUserException e)
                {
                    ModelState.AddModelError("", ErrorCodeToString(e.StatusCode));
                }
            }

            // If we got this far, something failed, redisplay form
            return(View(model));
        }
        private Employee CreateEmployee()
        {
            var newEmployee = new Employee();

            RavenSession.Store(newEmployee);
            return(newEmployee);
        }
示例#5
0
        private void GenerateApplicant(Postulation postulation)
        {
            //TODO: move it to an Action
            var applicant = new Applicant()
            {
                JobSearchId = postulation.JobSearchId,
                Email       = postulation.Email,
                FirstName   = postulation.FirstName,
                LastName    = postulation.LastName
            };

            RavenSession.Store(applicant);

            applicant.Notes = new List <ApplicantNote>();

            if (postulation.Curriculum != null)
            {
                var curriculum = GenerateAttachment(applicant, postulation.Curriculum);
                applicant.AddGeneralNote("Currículum", curriculum);
            }

            if (!string.IsNullOrEmpty(postulation.Comment))
            {
                applicant.AddGeneralNote("Nota de postulación:\n\n" + postulation.Comment);
            }

            //TODO change this when links are in place
            if (!string.IsNullOrEmpty(postulation.LinkedInUrl))
            {
                applicant.AddGeneralNote("Perfil de LinkedIn: " + postulation.LinkedInUrl);
            }
        }
示例#6
0
        public ActionResult Create()
        {
            var newJobSearch = new JobSearch();

            RavenSession.Store(newJobSearch);
            return(RedirectToAction("Edit", new { id = newJobSearch.Id }));
        }
        public virtual ActionResult Index(BlogConfig config)
        {
            if (ModelState.IsValid == false)
            {
                ViewBag.Message = ModelState.FirstErrorMessage();
                if (Request.IsAjaxRequest())
                {
                    return(Json(new { Success = false, ViewBag.Message }));
                }
                return(View(BlogConfig));
            }

            var current = RavenSession.Load <BlogConfig>(BlogConfig.Key);

            if (IsFuturePostsEncryptionOptionsChanged(current, config))
            {
                RemoveFutureRssAccessOnEncryptionConfigChange();
            }

            RavenSession.Advanced.Evict(current);
            RavenSession.Store(config, BlogConfig.Key);
            RavenSession.SaveChanges();

            OutputCacheManager.RemoveItem(MVC.Section.Name, MVC.Section.ActionNames.ContactMe);

            ViewBag.Message = "Configurations successfully saved!";
            if (Request.IsAjaxRequest())
            {
                return(Json(new { Success = true, ViewBag.Message }));
            }
            return(View(config));
        }
示例#8
0
        private Employee CreateEmployee(string name)
        {
            var newEmployee = new Employee(name);

            RavenSession.Store(newEmployee);
            return(newEmployee);
        }
        public ActionResult Config(Config model)
        {
            Settings settings;

            using (RavenSession.Advanced.DocumentStore.DisableAggressiveCaching())
            {
                settings = RavenSession.Load <Settings>(Settings.DefaultId);
            }
            if (settings == null)
            {
                return(RedirectToAction("Auth"));
            }

            if (!ModelState.IsValid)
            {
                return(ConfigView(settings, model));
            }

            Mapper.Map(model, settings);
            RavenSession.Store(settings);

            Response.RemoveOutputCacheItem(Url.Content("~/Widgets/AnalyticsSummary"));

            return(RedirectToAction("Index"));
        }
示例#10
0
        private void GenerateApplicant(Postulation postulation)
        {
            //TODO: move it to an Action
            var applicant = new Applicant()
            {
                JobSearchId     = postulation.JobSearchId,
                Email           = postulation.Email,
                FirstName       = postulation.FirstName,
                LastName        = postulation.LastName,
                TechnicalSkills = postulation.TechnicalSkills,
                LinkedInLink    = postulation.LinkedInUrl
            };

            RavenSession.Store(applicant);

            applicant.Notes = new List <NoteWithAttachment>();

            if (postulation.Curriculum != null)
            {
                var curriculum = GenerateAttachment(applicant, postulation.Curriculum);
                applicant.AddGeneralNote("Currículum", curriculum);
            }

            if (!string.IsNullOrEmpty(postulation.Comment))
            {
                applicant.AddGeneralNote("Nota de postulación:\n\n" + postulation.Comment);
            }
        }
示例#11
0
        private void CreateBoardAndDefinition(RegisterViewModel model, User user)
        {
            var exampleCard1 = new Card {
                Id = Guid.NewGuid().ToString(), Text = "Skapa en utmaningsbräda", Category = Category.Misc, Points = 1
            };
            var exampleCard2 = new Card {
                Id = Guid.NewGuid().ToString(), Text = "Skapa din första utmaning", Category = Category.Health, Points = 1
            };

            var boardDefinition = new BoardDefinition {
                Name  = model.BoardName,
                Cards = new List <Card> {
                    exampleCard1, exampleCard2
                }
            };

            RavenSession.Store(boardDefinition);

            var board = new Board {
                BoardName         = model.BoardName,
                BoardDefinitionId = boardDefinition.Id,
                UserName          = model.UserName,
                UserId            = user.Id,
                BoardActivityList = new List <Activity> {
                    new Activity {
                        CardId = exampleCard1.Id, Name = exampleCard1.Text, TimeStamp = DateTime.Now
                    }
                },
                IsPublic = true
            };

            RavenSession.Store(board);
        }
示例#12
0
        public ActionResult Create(string name)
        {
            var newApplicant = new Applicant(name);

            RavenSession.Store(newApplicant);
            return(RedirectToAction("Edit", new { id = newApplicant.Id }));
        }
示例#13
0
        public virtual async Task <ActionResult> ExternalLoginCallback(string returnUrl)
        {
            Session["Dummy"] = "Dummy";             // OWIN External Login hack

            Uri returnUri;

            Uri.TryCreate(returnUrl, UriKind.Absolute, out returnUri);

            var loginInfo = await AuthenticationManager.GetExternalLoginInfoAsync();

            if (loginInfo == null || returnUri == null)
            {
                return(returnUri != null ? (ActionResult)Redirect(returnUri.AbsoluteUri) : RedirectToRoute("homepage"));
            }

            var claimedIdentifier = loginInfo.Login.ProviderKey + "@" + loginInfo.Login.LoginProvider;
            var commenter         = RavenSession.Query <Commenter>()
                                    .FirstOrDefault(c => c.OpenId == claimedIdentifier) ?? new Commenter
            {
                Key    = Guid.NewGuid(),
                OpenId = claimedIdentifier,
            };

            SetCommenterValuesFromResponse(loginInfo, commenter);

            CommenterUtil.SetCommenterCookie(Response, commenter.Key.MapTo <string>());
            RavenSession.Store(commenter);

            return(Redirect(returnUri.AbsoluteUri));
        }
示例#14
0
        public ActionResult Index()
        {
            var exercises = RavenSession.Query <Exercise>().Where(x => x.Master).Take(1024);

            RavenSession.Advanced.MaxNumberOfRequestsPerSession = 10000;
            foreach (var exer in exercises)
            {
                var newMaster = new MasterExercise();

                newMaster.AccountId        = 0;
                newMaster.Name             = exer.Name;
                newMaster.Categories       = exer.Categories;
                newMaster.ClinicId         = 0;
                newMaster.Description      = exer.Description;
                newMaster.ExerciseDetails  = exer.ExerciseDetails;
                newMaster.MasterExerciseId = exer.Id;
                newMaster.Master           = true;
                newMaster.UserId           = 0;
                newMaster.VideoId          = exer.VideoId;
                newMaster.CreatedOn        = DateTime.Now;

                RavenSession.Store(newMaster);
            }

            RavenSession.SaveChanges();

            return(View());
        }
示例#15
0
        public ActionResult Edit(PostInput input, int id)
        {
            if (!ModelState.IsValid)
            {
                return(View("Edit", input));
            }

            var post = RavenSession.Load <Post>(id) ?? new Post();

            input.MapPropertiesToInstance(post);

            var user = RavenSession.GetCurrentUser();

            if (string.IsNullOrEmpty(post.AuthorId))
            {
                post.AuthorId = user.Id;
            }
            else
            {
                post.LastEditedByUserId = user.Id;
                post.LastEditedAt       = DateTimeOffset.Now;
            }

            RavenSession.Store(post);

            var postReference = post.MapTo <PostReference>();

            return(RedirectToAction("Details", new { Id = postReference.DomainId, postReference.Slug }));
        }
示例#16
0
        public ActionResult Update(PostInput input)
        {
            if (!ModelState.IsValid)
            {
                return(View("Edit", input));
            }

            var post = RavenSession.Load <Post>(input.Id) ?? new Post {
                CreatedAt = DateTimeOffset.Now
            };

            input.MapPropertiesToInstance(post);

            // Be able to record the user making the actual post
            var user = RavenSession.GetCurrentUser();

            if (string.IsNullOrEmpty(post.AuthorId))
            {
                post.AuthorId = user.Id;
            }
            else
            {
                post.LastEditedByUserId = user.Id;
                post.LastEditedAt       = DateTimeOffset.Now;
            }

            if (post.PublishAt == DateTimeOffset.MinValue)
            {
                var postScheduleringStrategy = new PostSchedulingStrategy(RavenSession, DateTimeOffset.Now);
                post.PublishAt = postScheduleringStrategy.Schedule();
            }

            // Actually save the post now
            RavenSession.Store(post);

            if (input.IsNewPost())
            {
                // Create the post comments object and link between it and the post
                var comments = new PostComments
                {
                    Comments = new List <PostComments.Comment>(),
                    Spam     = new List <PostComments.Comment>(),
                    Post     = new PostComments.PostReference
                    {
                        Id        = post.Id,
                        PublishAt = post.PublishAt,
                    }
                };

                RavenSession.Store(comments);

                // Once the Comments have been saved, update and save the post
                post.CommentsId = comments.Id;
                RavenSession.Store(post);
            }

            return(RedirectToAction("Details", new { Id = post.MapTo <PostReference>().DomainId }));
        }
示例#17
0
            public ActionResult Add(string name)
            {
                var sampleData = new SampleData {
                    CreatedAt = SystemTime.UtcNow, Name = name
                };

                RavenSession.Store(sampleData);
                return(RedirectToAction("Edit", new { id = sampleData.Id }));
            }
示例#18
0
        // POST api/assets
        public Object Post(Asset value)
        {
            var owner = ObtainCurrentOwner();

            value.OwnerId = owner.Id;
            RavenSession.Store(value);

            return(GetReturnSaveReturnDto(value));
        }
示例#19
0
 public ActionResult Create(LogEntry logentry)
 {
     if (!ModelState.IsValid)
     {
         return(View(logentry));
     }
     RavenSession.Store(logentry);
     return(RedirectToAction("Index"));
 }
 public ActionResult Edit(InsulinDosageModel dosageModel)
 {
     if (!ModelState.IsValid)
     {
         return(View(dosageModel));
     }
     RavenSession.Store(dosageModel);
     return(RedirectToAction("Details", dosageModel));
 }
 public ActionResult Edit(DiabetesLogEntryModel entryModel)
 {
     if (!ModelState.IsValid)
     {
         return(View(entryModel));
     }
     RavenSession.Store(entryModel);
     return(RedirectToAction("Details", entryModel));
 }
示例#22
0
        private void UpdateCalification(UpdateCalificationDto calification, EvaluationCalification storedCalification, bool finished)
        {
            // Update the calification comments and values
            storedCalification.Comments      = calification.Comments;
            storedCalification.Califications = calification.Items;
            storedCalification.Finished      = finished;

            // Update the EvaluationCalification document in the collection (DB)
            RavenSession.Store(storedCalification);
        }
示例#23
0
        public ActionResult Create(ExerciseViewModel postedModel)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    return(View(postedModel));
                }

                //this code could use some TLC

                var newExercise = new Exercise();

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


                if (!string.IsNullOrWhiteSpace(postedModel.VideoId))
                {
                    newExercise.VideoId = postedModel.VideoId.Trim();
                }

                Ownership.Assign(newExercise, this);

                if (this.ApplicationAdministrator)
                {
                    newExercise.Master = true;
                }
                newExercise.CreatedOn   = DateTime.Now;
                newExercise.Name        = postedModel.Name.Trim();
                newExercise.Description = postedModel.Description;

                RavenSession.Store(newExercise);
                RavenSession.SaveChanges();

                if (!string.IsNullOrWhiteSpace(postedModel.VideoId))
                {
                    var success = Thumbnailer.GenerateThumbs(newExercise.Id, newExercise.VideoId);
                    if (!success)
                    {
                        this.WarnUser("We couldn't generate a thumbnail image for this exercise.  The video id could be wrong or Vimeo may be not be " +
                                      "responding.  We'll try to generate the thumbnail again but it would be a good idea to double" +
                                      "check the video id. Sorry about that.");
                    }
                }

                HighFive("New exercise created ok.");

                return(RedirectToAction("List"));
            }
            catch
            {
                return(View(postedModel));
            }
        }
            public ActionResult Create(User user)
            {
                if (!ModelState.IsValid)
                {
                    return(View("Create", user));
                }

                RavenSession.Store(user);

                return(RedirectToAction("Index"));
            }
 public ActionResult Create(DiabetesLogEntryModel entryModel)
 {
     if (!ModelState.IsValid)
     {
         return(View(entryModel));
     }
     entryModel.InsulinDosages = new List <InsulinDosageModel>();
     entryModel.FoodItems      = new List <FoodItemModel>();
     RavenSession.Store(entryModel);
     return(RedirectToAction("Details", entryModel));
 }
示例#26
0
        public ActionResult QuickAttachment()
        {
            Applicant applicant;
            //The normal binding does not work
            var id   = RouteData.Values["id"] as string;
            var name = Request.Form["name"] as string;

            if (id == null)
            {
                applicant = new Applicant(name);
                RavenSession.Store(applicant);
            }
            else
            {
                applicant = RavenSession.Load <Applicant>(id);
                if (applicant == null)
                {
                    return(HttpNotFound());
                }
            }

            using (var attachmentReader = new RequestAttachmentReader(Request))
            {
                var attachments = attachmentReader
                                  .Select(x => ExecuteCommand(new SaveAttachment(applicant, x.Key, x.Value)))
                                  .ToArray();

                var notes = attachments.Select(x => new NoteWithAttachment()
                {
                    Attachment   = x,
                    Note         = "QuickAttachment!",
                    RealDate     = DateTime.Now,
                    RegisterDate = DateTime.Now
                });

                if (applicant.Notes == null)
                {
                    applicant.Notes = notes.ToList();
                }
                else
                {
                    applicant.Notes.AddRange(notes);
                }

                return(Json(new
                {
                    success = true,
                    entityId = applicant.Id,
                    editUrl = Url.Action("Edit", new { id = applicant.Id }),
                    attachment = attachments.FirstOrDefault(),
                    attachments = attachments
                }));
            }
        }
示例#27
0
        //
        // GET: /Scheduler/

        public ActionResult Index()
        {
            var schedule = RavenSession.Load <ScheduleSettings>("scheduleSettings/1");
            var data     = new List <EmailReminderData>();

            int delayHours = 4;

            if (schedule == null)
            {
                schedule = new ScheduleSettings {
                    Id = "scheduleSettings/1"
                }; RavenSession.Store(schedule); ViewBag.Message = "This is the first run!";
                ViewBag.Error = "First run, creating session";
                return(View());
            }


            if ((DateTime.Now - schedule.LastRun).TotalHours > delayHours)
            {
                try
                {
                    var logic = new ReminderHelper(RavenSession, Server.MapPath("/Views/Templates/"));

                    var reminders = logic.GetAllRemindersDueBefore(DateTime.Now);
                    var msgs      = logic.ComposeMessages(reminders);
                    ViewBag.Messages = msgs;
                    var emails = logic.SendEmails(msgs);
                    ViewBag.SentMessages = emails;
                    logic.UpdateMsgCount(reminders);
                }
                catch (Exception ex)
                {
                    ViewBag.Error = ex.Message;
                }

                ViewBag.Message = "Last run: " + schedule.LastRun;

                if (data.Count > 0)
                {
                    string emailText = GetEmailText(data);
                    RavenSession.Store(new TempTextEmail {
                        Text = emailText
                    });
                }
                schedule.LastNumberOfNotifications = data.Count;
                schedule.LastRun = DateTime.Now;
                RavenSession.SaveChanges();
            }
            else
            {
                ViewBag.Error = "Scheduler will not run before" + (delayHours - (DateTime.Now - schedule.LastRun).TotalHours).ToString() + " hours";
            }
            return(View(data));
        }
        public ActionResult Create(Book book)
        {
            if (!ModelState.IsValid)
            {
                return(View(book));
            }

            RavenSession.Store(book);

            return(Json("Book was successfully added and was assigned the ID " + book.Id, JsonRequestBehavior.AllowGet));
        }
示例#29
0
        public ActionResult UpdateProject(Project existingProject)
        {
            var isValid = ModelState.IsValid && ValidateProject(existingProject, ModelState);

            if (isValid)
            {
                RavenSession.Store(existingProject);
                RavenSession.SaveChanges();
            }

            return(GetJsonResult(existingProject));
        }
示例#30
0
        public ActionResult CreateUserStory(UserStory newUserStory)
        {
            if (ModelState.IsValid)
            {
                RavenSession.Store(newUserStory);
                RavenSession.SaveChanges();

                DomainEventService.PublishUserStoryCreated(newUserStory);
            }

            return(GetJsonResult(newUserStory));
        }