示例#1
0
        public MenteeModel AddMentee(MenteeModel model, int userId)
        {
            //Get category
            var query = from c in _context.Categories
                        where c.CategoryName == model.Category
                        select c;

            //Select first matching record
            var category = query.FirstOrDefault();

            //Get User from database
            var user = _context.Users.Find(userId);

            //Check if record is null
            if (user == null)
            {
                throw new Exception("This user doesnt exist");
            }

            var mentee = new Mentee
            {
                UserId   = user.UserId,
                Birthday = model.Birthday,
                Gender   = model.Gender,
                Address  = model.Address,
                MobileNo = model.MobileNo,
                Bio      = model.Bio,
                Category = category
            };

            _context.Mentees.Add(mentee);
            _context.SaveChanges();
            return(model);
        }
示例#2
0
        public void AssignMentor(MenteeModel model, int mentorId)
        {
            //Check if Mentee already has mentor
            var exists = _repo.Mentored(model.UserId);

            if (exists)
            {
                throw new Exception("Mentee Already Has a Mentor");
            }

            _repo.AssignMentor(model.UserId, mentorId);
        }
示例#3
0
        public MenteeModel AddMentee(MenteeModel model, int userId)
        {
            //Check if Mentee already exists
            var mentee = _repo.GetMentee(userId);

            if (mentee != null)
            {
                //If there is already a mentee
                throw new Exception("Mentee Records Already Exist");
            }
            mentee = _repo.AddMentee(model, userId);
            return(mentee);
        }
示例#4
0
        public void AssignMentor()
        {
            //Arrange
            var mockRepo = new MockMenteeRepository();
            var manager = new MenteeManager(mockRepo);

            //Test Data
            var mentee = new MenteeModel
            {
                Category = "Art"
            };
            //Act
            manager.AddMentee(mentee, 1);
            manager.AssignMentor(mentee, 11);
            //Assert
            Assert.IsTrue(mockRepo.Mentored(mentee.UserId), "Mentor was not assigned");
        }
示例#5
0
 public void AddMentee()
 {
     //Arrange
     var mockRepo = new MockMenteeRepository();
     var manager = new MenteeManager(mockRepo);
     //Test Data
     var mentee = new MenteeModel
     {
         Bio = "My test bio",
         Address = "Lagos",
         Gender = "Lagos",
     };
     //Act
     manager.AddMentee(mentee, 1);
     //Assert
     Assert.IsTrue(manager.GetMentee(mentee.UserId) != null, "Mentee was not created");
 }
示例#6
0
        public MenteeModel GetMentee(int userId)
        {
            //Get user from database

            var record = _context.Mentees.Find(userId);

            //Check if user Exists
            if (record != null)
            {
                //transform Mentee record to MenteeModel
                var model = new MenteeModel
                {
                    UserId = record.UserId,
                    User   = new UserModel
                    {
                        FirstName = record.User.FirstName,
                        LastName  = record.User.LastName,
                        Email     = record.User.Email
                    },

                    Address  = record.Address,
                    Birthday = record.Birthday,
                    Gender   = record.Gender,
                    MobileNo = record.MobileNo,
                    Bio      = record.Bio,
                    Category = record.Category.CategoryName
                };
                if (record.Mentor != null)
                {
                    model.Mentor = new MentorModel
                    {
                        User = new UserModel
                        {
                            FirstName = record.Mentor.User.FirstName,
                            LastName  = record.Mentor.User.LastName,
                            Email     = record.Mentor.User.Email
                        }
                    };
                }

                return(model);
            }

            return(null);
        }
示例#7
0
        public ActionResult Edit(MenteeModel model)
        {
            var identity = User.Identity.GetUserIdentity();

            if (ModelState.IsValid)
            {
                try
                {
                    _mentee.EditMentee(model, identity.UserId);
                    return(RedirectToAction("userprofile"));
                }

                catch (Exception ex)
                {
                    ModelState.AddModelError("Failed to save", ex.Message);
                }
            }
            return(View(model));
        }
示例#8
0
        public MenteeModel EditMentee(MenteeModel model, int userId)
        {
            var mentee = _context.Mentees.Find(userId);

            if (mentee != null)
            {
                //map model fields to mentee
                mentee.User.FirstName = model.User.FirstName;
                mentee.User.LastName  = model.User.LastName;

                mentee.MobileNo = model.MobileNo;
                mentee.Address  = model.Address;
                mentee.Bio      = model.Bio;
                mentee.Birthday = model.Birthday;
                mentee.MobileNo = model.MobileNo;

                _context.Entry(mentee).State = EntityState.Modified;
                _context.SaveChanges();
            }

            return(new MenteeModel());
        }
示例#9
0
        public ActionResult AddBio(MenteeBioModel model, int userId)
        {
            //Get user by id
            var user = _user.GetUserById(userId);
            //Populate Category Dropdown List
            var categories = _user.GetCategories();

            model.Categories = GetSelectListItems(categories);

            if (ModelState.IsValid)
            {
                try
                {
                    //Map MenteeBio info to mentee table
                    var mentee = new MenteeModel
                    {
                        UserId   = user.UserId,
                        Address  = model.Address,
                        Birthday = model.Birthday,
                        Gender   = model.Gender,
                        MobileNo = model.MobileNo,
                        Bio      = model.Bio,
                        Category = model.Category
                    };

                    _mentee.AddMentee(mentee, user.UserId);
                    //Trying to log user in immediately after adding profile
                    var identity = user.GetUserIdentity();
                    AuthenticationManager.SignIn(identity);
                    return(RedirectToAction("index"));
                }
                catch (Exception ex)
                {
                    ModelState.AddModelError("Invalid Reg", ex.Message);
                }
            }
            return(View(model));
        }
示例#10
0
 public MenteeModel EditMentee(MenteeModel model, int userId)
 {
     throw new NotImplementedException();
 }
示例#11
0
 public MenteeModel AddMentee(MenteeModel model, int userId)
 {
     model.UserId = userId;
     _mentees.Add(model);
     return(model);
 }
示例#12
0
 public MenteeModel EditMentee(MenteeModel model, int userId)
 {
     return(_repo.EditMentee(model, userId));
 }