public ActionResult ModifyAdoptInfoSend(ModifyAdoptInfoViewModel model) { try { //檔案處理封面照片 if (model.CoverPhoto != null) { model.PhotoExtension = Path.GetExtension(model.CoverPhoto.FileName); using (BinaryReader reader = new BinaryReader(model.CoverPhoto.InputStream)) { model.CoverPhotoByte = reader.ReadBytes(model.CoverPhoto.ContentLength); } } bool IsSuccess = _Repo.ModifyAdoptInfo(model); if (IsSuccess) { ViewBag.Message = "修改成功!"; } else { ViewBag.Message = "修改失敗!"; } } catch (Exception ex) { ViewBag.Message = "修改失敗!原因:" + ex.Message; } return(View("ModifyAdoptInfo", model)); }
//會員取得認養動物修改明細 public ModifyAdoptInfoViewModel ModifyAdoptDetail(int AnimalID) { ModifyAdoptInfoViewModel returnItem = new ModifyAdoptInfoViewModel(); try { PetPetAnimalEntities _ctx = new PetPetAnimalEntities(); AnimalInfo query = _ctx.AnimalInfo.Where(x => x.AnimalID == AnimalID).FirstOrDefault(); returnItem = new ModifyAdoptInfoViewModel(query); } catch (Exception ex) { return(returnItem); } return(returnItem); }
/// <summary> /// 修改認養資料 /// </summary> /// <param name="model"></param> /// <returns></returns> public bool ModifyAdoptInfo(ModifyAdoptInfoViewModel model) { bool IsSuccess; try { PetPetAnimalEntities _ctx = new PetPetAnimalEntities(); var animal = _ctx.AnimalInfo.Where(x => x.AnimalID == model.AnimalID).FirstOrDefault(); animal.Age = model.AgeAndUnit; animal.CityLocation = model.CityLocation; animal.Contacter = model.Contacter; animal.ContacterEmail = model.ContacterEmail; animal.ContacterPhone = model.ContacterPhone; animal.Gender = (int)model.Gender; animal.Header = model.CoverHeader; animal.Height = model.Height; animal.Intro = model.Introduction; animal.IsSpay = model.IsSpay; animal.Length = model.Length; animal.Name = model.Name; animal.Personality = model.Personality; if (model.CoverPhotoByte != null) { animal.Photo = model.CoverPhotoByte; animal.PhotoExt = model.PhotoExtension; } animal.ShortIntro = model.CoverIntro; animal.SpecialNeed = model.SpecialNeed; animal.Unit = model.Unit; animal.Weight = model.Weight; animal.IsOpen = model.UpdateIsOpen; animal.Type = model.Type; IsSuccess = _ctx.SaveChanges() > 0; } catch (Exception ex) { IsSuccess = false; } return(IsSuccess); }
/// <summary> /// 修改認養資料(畫面編輯) /// </summary> /// <returns></returns> public ActionResult ModifyAdoptInfo(MemberViewAdoptDetailViewModel modeViewl) { ModifyAdoptInfoViewModel model = new ModifyAdoptInfoViewModel(); try { model = _Repo.ModifyAdoptDetail(modeViewl.AnimalID); if (model.CoverPhotoByte != null) { byte[] photoByte = model.CoverPhotoByte; model.Base64Photo = Convert.ToBase64String(photoByte); } else { model.Base64Photo = ""; } } catch (Exception ex) { throw ex; } return(View(model)); }