Exemplo n.º 1
0
        public ActionResult Create(MentorViewModel viewModel)
        {
            if (ModelState.IsValid)
            {
                // Go forward
                Person  mentor   = new Person(viewModel.Person);
                Address homeAddr = new Address(viewModel.HomeAddress);
                Address workAddr = new Address(viewModel.WorkAddress);

                // Update some codes
                mentor.PersonTypeId = DomainHelper.GetIdByKeyValue(ref _db, "PersonType", "Mentor");
                mentor.StatusId     = DomainHelper.GetIdByKeyValue(ref _db, "StatusCode", "Active");

                // Add the objects to the database
                this._db.People.Add(mentor);
                this._db.Addresses.Add(homeAddr);
                this._db.Addresses.Add(workAddr);

                // Save the data
                this._db.SaveChanges();

                return(RedirectToAction("Create"));
            }
            else
            {
                var errors = ModelState.Where(v => v.Value.Errors.Any());
            }

            return(View(viewModel));
        }
Exemplo n.º 2
0
        public ActionResult Edit(MentorViewModel viewModel)
        {
            if (ModelState.IsValid)
            {
                // Go forward
            }

            return(View(viewModel));
        }
Exemplo n.º 3
0
        public void Create(MentorViewModel mentor)
        {
            if (mentor == null)
            {
                throw new Exception("mentor not found");
            }

            _mentorRepository.Create(mentor.ToDomain());
        }
Exemplo n.º 4
0
        public async Task <ActionResult> Mentor(string id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            MentorViewModel viewModel = await _service.GetMentorAssignmentsViewModelAsync(id);

            return(View(viewModel));
        }
Exemplo n.º 5
0
        public async Task <MentorViewModel> GetMentorAssignmentsViewModelAsync(string mentorId)
        {
            IEnumerable <AssignmentDTO> assignments = await assignmentService.GetByCreatorsIdAsync(mentorId);

            MentorDTO mentor = await mentorService.GetByIdAsync(mentorId);

            MentorViewData  viewModelData = new MentorViewData(assignments, mentor);
            MentorViewModel viewModel     = viewFactory.CreateView <MentorViewData, MentorViewModel>(viewModelData);

            return(viewModel);
        }
 public ActionResult CreateMentor(MentorViewModel mentor)
 {
     try
     {
         _mentorService.Create(mentor);
         return(Ok());
     }
     catch (Exception ex)
     {
         return(BadRequest(ex.Message));
     }
 }
Exemplo n.º 7
0
 public static Mentor ToDomain(this MentorViewModel model)
 {
     return(new Mentor
     {
         ID = model.ID,
         FirstName = model.FirstName,
         LastName = model.LastName,
         Email = model.Email,
         YearsOfService = model.YearsOfService,
         Specialty = model.Specialty,
         Telephone = model.Telephone,
         UserId = model.UserId
     });
 }
Exemplo n.º 8
0
        public static MentorViewModel GetMentorById(ref DAO.ApplicationContext context, int personId)
        {
            MentorViewModel mentor = new MentorViewModel();

            mentor.Person = (from r in context.People
                             where r.id == personId
                             select r).First();

            mentor.HomeAddress = AddressHelper.GetAddressByPersonAndType(ref context, personId, "Home");
            mentor.WorkAddress = AddressHelper.GetAddressByPersonAndType(ref context, personId, "Work");
            mentor.MinistryId  = MinistryHelper.GetMinistryByPersonId(ref context, personId);

            return(mentor);
        }
 public ActionResult UpdateMentor(MentorViewModel mentor)
 {
     try
     {
         if (!ModelState.IsValid)
         {
             throw new Exception(ModelState.ToString());
         }
         _mentorService.Update(mentor);
         return(Ok());
     }
     catch (Exception ex)
     {
         return(BadRequest(ex.Message));
     }
 }
Exemplo n.º 10
0
        public void Update(MentorViewModel model)
        {
            var mentor = _mentorRepository.FindById(model.ID);

            if (mentor == null)
            {
                throw new Exception("mentor not found");
            }

            mentor.FirstName      = model.FirstName;
            mentor.LastName       = model.LastName;
            mentor.Specialty      = model.Specialty;
            mentor.Telephone      = model.Telephone;
            mentor.YearsOfService = model.YearsOfService;
            mentor.Email          = model.Email;

            _mentorRepository.Update(mentor);
        }
        public async Task <IActionResult> Post([FromBody] MentorViewModel model)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    var mentorEmail =
                        $"{model.MentorFirstName.ToLower()}.{model.MentorLastName.ToLower()}@meticulousmentoring.com";
                    var mentor = await this._userManager.FindByEmailAsync(mentorEmail);

                    if (mentor == null)
                    {
                        mentor = new MeticulousUser()
                        {
                            UserName  = mentorEmail,
                            Email     = mentorEmail,
                            FirstName = model.MentorFirstName,
                            LastName  = model.MentorLastName
                        };

                        var mentorResult =
                            await _userManager.CreateAsync(mentor, $"{model.MentorLastName}{DateTime.Now.Year}!");

                        if (mentorResult == IdentityResult.Success)
                        {
                            await _userManager.AddToRoleAsync(mentor, "Mentor");

                            model.MentorId = mentor.Id;
                            var newMentor = this.mapper.Map <MentorViewModel, Mentor>(model);

                            _ctx.TimeLine.Add(new Timeline
                            {
                                user_id       = model.MentorId,
                                detail        = "Joined Program",
                                timeline_date = DateTime.Now
                            });

                            _ctx.Addresses.Add(model.MentorAddress);
                            await _ctx.SaveChangesAsync();

                            newMentor.mentees.Clear();

                            var mentee_names =
                                model.MentorMentees.Select(x => x.MenteeFirstName + ' ' + x.MenteeLastName);

                            var menteeStrings = string.Join(',', mentee_names);

                            foreach (var mentee in model.MentorMentees)
                            {
                                var menteeToAdd = _ctx.Mentees.Single(x => x.id == mentee.MenteeId);
                                menteeToAdd.modified_on = DateTime.Now;
                                newMentor.mentees.Add(menteeToAdd);

                                _ctx.TimeLine.Add(new Timeline
                                {
                                    user_id       = mentee.MenteeId,
                                    detail        = $"Matched with {model.MentorFirstName} {model.MentorLastName}",
                                    timeline_date = DateTime.Now
                                });
                            }

                            _ctx.TimeLine.Add(new Timeline
                            {
                                user_id       = model.MentorId,
                                detail        = $"Matched with mentee(s) {menteeStrings}",
                                timeline_date = DateTime.Now
                            });

                            newMentor.email       = mentorEmail;
                            newMentor.created_on  = DateTime.Now;
                            newMentor.modified_on = DateTime.Now;
                            this.mentorRepository.AddMentor(newMentor);
                            if (this.mentorRepository.SaveAll())
                            {
                                return(Created(
                                           $"/api/mentors/{newMentor.id}",
                                           this.mapper.Map <Mentor, MentorViewModel>(newMentor)));
                            }
                        }
                    }
                }
                else
                {
                    return(this.BadRequest(ModelState));
                }
            }
            catch (Exception e)
            {
                this.logger.LogError($"Could not save Mentor data: {e}");
            }
            return(this.BadRequest("Failed to save new Mentor data"));
        }
Exemplo n.º 12
0
        // This method returns the Edit View
        public ActionResult Edit(int id)
        {
            MentorViewModel viewModel = MentorHelper.GetMentorById(ref _db, id);

            return(View(viewModel));
        }