public void AddMentor(MentorModel model) { //Get Category var category = from c in _context.Categories where c.CategoryName == model.Category select c; //Check if mentor record already exists var query = from user in _context.Mentors where user.UserId == model.UserId select user; var record = query.FirstOrDefault(); //Add Mentor Record if (record != null) { throw new Exception("Mentor Record Already Exists"); } var mentor = new Mentor { UserId = model.UserId, Birthday = new DateTime(2000, 10, 5), CategoryId = category.FirstOrDefault().CategoryId, }; _context.Mentors.Add(mentor); _context.SaveChanges(); }
public async Task <IActionResult> Delete(RequestDataModel request) { var settings = new JsonSerializerSettings(); var searchObject = new MentorModel { }; settings.DateFormatString = "dd/MM/yyyy"; searchObject = JsonConvert.DeserializeObject <MentorModel>(request.model, settings); var mentor = new MentorModel(); mentor = searchObject; mentor.LastModifyDate = DateTime.Now; var hostAPI = "https://localhost:44322"; var rs = await ApiProvider.PostAsync <int>(hostAPI, ApiConstant.DeleteMentor, mentor); if (rs == Constant.ReturnExcuteFunction.Success) { return(Json(new { messege = "Thành công !" })); } else { return(Json(new { messege = "Thất bại!" })); } }
public MentorModel Update(MentorModel updatedMentor) { var entity = db.Mentors.Attach(updatedMentor); entity.State = EntityState.Modified; return(updatedMentor); }
public async Task <ActionResult <MentorModel> > PostMentorModel(MentorModel mentorModel) { _context.Mentors.Add(mentorModel); await _context.SaveChangesAsync(); return(CreatedAtAction("GetMentorModel", new { id = mentorModel.Id }, mentorModel)); }
public int CreateOrUpdate(MentorModel model) { string msgError = ""; try { var result = _dbHelper.ExecuteScalarSProcedureWithTransaction(out msgError, "MENTOR_INSERT_OR_UPDATE", "@id", model.Id, "@mentor_code", model.Mentor_Code, "@mentor_name", model.Mentor_Name, "@position", model.Position, "@introduce", model.Introduce, "@avatar", model.Avatar, "@description", model.Description, "@active", model.Active); if ((result != null && !string.IsNullOrEmpty(result.ToString())) || !string.IsNullOrEmpty(msgError)) { throw new Exception(Convert.ToString(result) + msgError); } else { return(Constant.ReturnExcuteFunction.Success); } } catch (Exception ex) { throw ex; } }
public async Task <IActionResult> PutMentorModel(int id, MentorModel mentorModel) { if (id != mentorModel.Id) { return(BadRequest()); } _context.Entry(mentorModel).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!MentorModelExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public IActionResult OnGet(int mentorId) { MentorModel = mentorData.GetById(mentorId); if (MentorModel == null) { return(RedirectToPage("./NotFound")); } return(Page()); }
public void AddMentor(MentorModel model) { var mentor = new MentorModel { UserId = model.UserId, Category = model.Category }; Mentors.Add(mentor); }
public void AddMentor(MentorModel model) { //validate model model.Validate(); //Check if mentor record already exists var mentor = _repo.GetMentor(model.UserId); if (mentor != null) { throw new Exception("This record already exists!!!"); } _repo.AddMentor(model); }
public MentorModel Update(MentorModel updatedMentor) { var mentor = mentors.SingleOrDefault(m => m.Id == updatedMentor.Id); if (mentor != null) { mentor.Name = updatedMentor.Name; mentor.Surname = updatedMentor.Surname; mentor.Email = updatedMentor.Email; mentor.Phone = updatedMentor.Phone; mentor.Education = updatedMentor.Education; mentor.Experience = updatedMentor.Experience; mentor.Technologies = updatedMentor.Technologies; } return(mentor); }
public IActionResult OnGet(int?mentorId) { EducationType = htmlHelper.GetEnumSelectList <EducationTypeEnum>(); TechnologiesStack = htmlHelper.GetEnumSelectList <TechnologiesStackEnum>(); if (mentorId.HasValue) { Mentor = mentorData.GetById(mentorId.Value); } else { Mentor = new MentorModel(); } if (Mentor == null) { return(RedirectToPage("./NotFound")); } return(Page()); }
public ActionResult Edit(MentorModel model) { var identity = User.Identity.GetUserIdentity(); if (ModelState.IsValid) { try { _mentor.EditMentor(model, identity.UserId); return(RedirectToAction("userprofile")); } catch (Exception ex) { ModelState.AddModelError("Failed to save", ex.Message); } } return(View(model)); }
public async Task <IActionResult> GetByID(RequestDataModel request) { var settings = new JsonSerializerSettings(); var searchObject = new MentorModel { }; settings.DateFormatString = "dd/MM/yyyy"; searchObject = JsonConvert.DeserializeObject <MentorModel>(request.model, settings); var mentor = new MentorModel(); mentor = searchObject; mentor.LastModifyDate = DateTime.Now; var hostAPI = "https://localhost:44322"; var rs = await ApiProvider.PostAsync <MentorModel>(hostAPI, ApiConstant.GetMentorId, mentor); return(Json(rs)); }
public async Task <IActionResult> CreateOrUpdate(RequestDataModel request) { var settings = new JsonSerializerSettings(); var searchObject = new MentorModel { }; settings.DateFormatString = "dd/MM/yyyy"; string fileName = null; string orgFileName = ContentDispositionHeaderValue.Parse(request.files.ContentDisposition).FileName.Value; fileName = DateTime.Now.ToFileTime() + Path.GetExtension(orgFileName); searchObject = JsonConvert.DeserializeObject <MentorModel>(request.model, settings); var mentor = new MentorModel(); mentor = searchObject; mentor.Avatar = fileName; mentor.LastModifyDate = DateTime.Now; var hostAPI = "https://localhost:44322"; var rs = await ApiProvider.PostAsync <int>(hostAPI, ApiConstant.CreateMentor, mentor); if (rs == Constant.ReturnExcuteFunction.Success) { string fullPath = GetFullPathOfFile(fileName); // Create the directory. Directory.CreateDirectory(Directory.GetParent(fullPath).FullName); // Save the file to the server. await using FileStream output = System.IO.File.Create(fullPath); await request.files.CopyToAsync(output); return(Json(new { messege = "Thành công !" })); } else { return(Json(new { messege = "Thất bại!" })); } }
public int Delete(MentorModel model) { string msgError = ""; try { var result = _dbHelper.ExecuteScalarSProcedureWithTransaction(out msgError, "sp_mentor_delete", "@id", model.Id); if ((result != null && !string.IsNullOrEmpty(result.ToString())) || !string.IsNullOrEmpty(msgError)) { throw new Exception(Convert.ToString(result) + msgError); } else { return(Constant.ReturnExcuteFunction.Success); } } catch (Exception ex) { throw ex; } }
public ActionResult MentorDetails(int id) { var userInfo = UserHelper.GetCurrentUserInfo(); if (userInfo.IsInRole(UserRoleCode.Career)) { var mentor = _mentorService.Search(m => m.Id == id).FirstOrDefault(); if (mentor != null) { var mentorModel = new MentorModel { Id = mentor.Id, CurrentActivity = mentor.CurrentActivity, Email = mentor.User.Email, Expectations = mentor.Expectations, Location = mentor.User.Location, MentoringTarget = mentor.MentoringTarget, Name = mentor.User.Name, NickName = mentor.User.NickName, OtherTopic = mentor.OtherTopic, Seniority = mentor.User.Seniority, Topics = mentor.Topic.Select(t => new TopicModel { Checked = false, Description = t.Description, Id = t.Id }).ToList(), Status = mentor.Status, MaxMentees = mentor.MaxMentees, MeetingsMode = EnumExtension.GetEnumDescription(mentor.MeetingsMode) }; return(View(mentorModel)); } } else { return(View("Unauthorized")); } return(null); }
public MentorModel EditMentor(MentorModel model, int userId) { var mentor = _context.Mentors.Find(userId); if (mentor != null) { //map model fields to mentor mentor.User.FirstName = model.User.FirstName; mentor.User.LastName = model.User.LastName; mentor.Address = model.Address; mentor.Gender = model.Gender; mentor.Bio = model.Bio; mentor.Birthday = model.Birthday; mentor.MobileNo = model.MobileNo; _context.Entry(mentor).State = EntityState.Modified; _context.SaveChanges(); } return new MentorModel(); }
public async Task <IActionResult> GetData(RequestDataModel request) { var mentorModelParamater = new MenTorModelParameter(); var settings = new JsonSerializerSettings(); var searchObject = new MentorModel { }; settings.DateFormatString = "dd/MM/yyyy"; searchObject = JsonConvert.DeserializeObject <MentorModel>(request.model, settings); var page = new PageParameter { PageIndex = request.start, PageSize = request.length }; mentorModelParamater.Page = page; mentorModelParamater.Data = searchObject; var hostAPI = "https://localhost:44322"; var data = await ApiProvider.PostAsync <MenTorReturnModel>(hostAPI, ApiConstant.GetAllMentor, mentorModelParamater); return(Json(data)); }
//This Method uses query to get a single mentor from the database public MentorModel GetMentor(int userId) { //Get mentor by userId var query = from user in _context.Mentors where user.UserId == userId select user; var mentor = query.FirstOrDefault(); if (mentor != null) { var model = new MentorModel { UserId = mentor.UserId, User = new UserModel { FirstName = mentor.User.FirstName, LastName = mentor.User.LastName, Email = mentor.User.Email }, Address = mentor.Address, Bio = mentor.Bio, Birthday = mentor.Birthday, Category = mentor.Category.CategoryName, Gender = mentor.Gender, MobileNo = mentor.MobileNo }; return model; } return null; }
public ActionResult AddBio(MentorBioModel model) { //Get user by id var user = User.Identity.GetUserIdentity(); if (ModelState.IsValid) { //map out mentor model var mentor = new MentorModel { UserId = user.UserId, Bio = model.Bio, MobileNo = model.MobileNo, Address = model.Address, Gender = model.Gender, Birthday = model.Birthday, User = new UserModel { FirstName = user.FirstName, LastName = user.LastName } }; try { _mentor.EditMentor(mentor, user.UserId); return(RedirectToAction("userprofile")); } catch (Exception ex) { ModelState.AddModelError("Invalid Reg", ex.Message); } } return(View(model)); }
public int Delete([FromBody] MentorModel model) { return(_bus.Delete(model)); }
public MentorModel GetDataID([FromBody] MentorModel model) { return(_bus.GetDataByID(model.Id)); }
public MentorModel Add(MentorModel newMentor) { db.Add(newMentor); return(newMentor); }
public MentorModel Add(MentorModel newMentor) { mentors.Add(newMentor); newMentor.Id = mentors.Max(m => m.Id) + 1; return(newMentor); }
public void EditMentor(MentorModel model, int userId) { _repo.EditMentor(model, userId); }
public int CreateOrUpdate(MentorModel model) { return(_res.CreateOrUpdate(model)); }
public int Delete(MentorModel model) { return(_res.Delete(model)); }
public int CreateOrUpdate([FromBody] MentorModel model) { return(_bus.CreateOrUpdate(model)); }
public MentorModel EditMentor(MentorModel model, int userId) { throw new NotImplementedException(); }