public UpdateCoach GetCoachInfo(string MemberId) { var coach = new Coach(); GetUserPara para = new GetUserPara() { MemberId = MemberId }; string returnStr = ShareService.Instance.SendApi("Member/GetCoachInfo", JsonConvert.SerializeObject(para)); coach = JsonConvert.DeserializeObject <Coach>(returnStr); UpdateCoach model = new UpdateCoach(); model.OriginArea = coach.Area;//存原始資料 再清空 model.OriginTrainProgram = coach.TrainingProgramId; model.OriginCourse = coach.CourseId; model.OriginExperience = coach.Experience; model.OriginLicense = coach.License; model.OriginCompetition = coach.Competiton; coach.Area = null; coach.TrainingProgramId = null; coach.CourseId = null; coach.Experience = null; coach.License = null; coach.Competiton = null; model.User = coach; return(model); }
// GET: Coach/Update/5 public ActionResult Update(int id) { Coach selectedCoach = db.Coaches.SqlQuery("select * from coaches where coachid = @id", new SqlParameter("@id", id)).FirstOrDefault(); UpdateCoach UpdateCoachViewModel = new UpdateCoach(); UpdateCoachViewModel.Coach = selectedCoach; return(View(UpdateCoachViewModel)); }
public Result Update(UpdateCoach model) { var result = new Result(); try { result = strategy.Update(model.User); if (result.ReturnNo == 1) { //地區 取差集看要新增或刪掉 result = LoopReflectionOpera(ref result, "InsertUserArea", model.User.MemberId, model.User.Area, model.OriginArea); result = LoopReflectionOpera(ref result, "DeleteUserArea", model.User.MemberId, model.OriginArea, model.User.Area); //課程 result = LoopReflectionOpera(ref result, "InsertCoachCourse", model.User.MemberId, model.User.CourseId, model.OriginCourse); result = LoopReflectionOpera(ref result, "DeleteCoachCourse", model.User.MemberId, model.OriginCourse, model.User.CourseId); //訓練 result = LoopReflectionOpera(ref result, "InsertTrainingProgram", model.User.MemberId, model.User.TrainingProgramId, model.OriginTrainProgram); result = LoopReflectionOpera(ref result, "DeleteTrainingProgram", model.User.MemberId, model.OriginTrainProgram, model.User.TrainingProgramId); //證照 result = LoopReflectionOpera(ref result, "InsertCoachLicense", model.User.MemberId, model.User.License, model.OriginLicense); result = LoopReflectionOpera(ref result, "DeleteCoachLicense", model.User.MemberId, model.OriginLicense, model.User.License); //經驗 result = LoopReflectionOpera(ref result, "InsertCoachExperience", model.User.MemberId, model.User.Experience, model.OriginExperience); result = LoopReflectionOpera(ref result, "DeleteCoachExperience", model.User.MemberId, model.OriginExperience, model.User.Experience); //比賽 result = LoopReflectionOpera(ref result, "InsertCoachCompetiton", model.User.MemberId, model.User.Competiton, model.OriginCompetition); result = LoopReflectionOpera(ref result, "DeleteCoachCompetiton", model.User.MemberId, model.OriginCompetition, model.User.Competiton); } //更新照片 if (!string.IsNullOrEmpty(model.User.Image)) { result = UpdateUserPhoto(model.User.MemberId, model.User.Image); } } catch (Exception ex) { LogService.LogTxt("更新資料例外錯誤" + ex.ToString()); result.ReturnNo = -99; result.Message = "更新資料例外錯誤"; } return(result); }
public ActionResult UpdateCoach() { UpdateService service = new UpdateService(); UpdateCoachViewModel model = new UpdateCoachViewModel(); if (LoginState) { string City = string.Empty; string Area = string.Empty; string Address = string.Empty; User user = GetMemberInfo(); string MemberId = user.MemberId; UpdateCoach updateModel = service.GetCoachInfo(MemberId); string[] AddressArray = updateModel.User.Address.Split('|'); if (AddressArray.Length == 3) { City = AddressArray[0]; Area = AddressArray[1]; updateModel.User.Address = AddressArray[2]; } model.addressCityList = new SelectList(service.GetCity(City), "Value", "Text"); model.addresAreaList = new SelectList(service.GetArea(), "Value", "Text", Area); model.AreaList = new MultiSelectList(service.GetCity(updateModel.OriginArea.ToArray()), "Value", "Text", updateModel.OriginArea); model.CourseList = new MultiSelectList(service.GetCourse(updateModel.OriginCourse.ToArray()), "Value", "Text", updateModel.OriginCourse); model.TrainingProgramList = new MultiSelectList(service.GetTrainingProgram(updateModel.OriginTrainProgram.ToArray()), "Value", "Text", updateModel.OriginTrainProgram); model.UpdateModel = updateModel; } else { return(RedirectToAction("Login", "Home")); } return(View(model)); }
public Result UpdateCoach(UpdateCoach model) { return(coach.Update(model)); }