public ActionResult EditAdditionalInfo(CareHome careHome, HttpPostedFileBase file) { if (file != null && file.ContentLength > 200000) { ModelState.AddModelError("", "アップロードできる画像のサイズは200kBまでです。"); } ModelState.Remove("CareHomeCode"); if (ModelState.IsValid) { var home = db.CareHomes.Find(careHome.CareHomeId); home.Region = careHome.Region; home.Traits = careHome.Traits; home.Messages = careHome.Messages; if (file != null) { BlobHelper.DeleteIfExists("mediafile", home.MediaFileDataId); home.MediaFileDataId = BlobHelper.Upload("mediafile", file, file.FileName); } db.SaveChanges(); Log(LogType.CareHome, "追加情報を更新しました。"); Flash("保存しました。"); return(RedirectToAction("CareHomeMenu", "Home")); } return(View(careHome)); }
public ActionResult Edit(string code, [Bind(Include = "CareManagerId,CareHomeId,Email,MediaFileDataId,Name,Gender,Age,Licensed,Licenses,CurrentPatients,AllowNewPatient,Career,Messages,BlogUrls,TotalRating,ReviewsCount,Rating,Birthday")] CareManager caremanager, HttpPostedFileBase file, int year, int month, int day) { // Checks file size. if (file != null && file.ContentLength > 200000) { ModelState.AddModelError("", "アップロードできる画像のサイズは200kBまでです。"); } // Sets Dec. 31th. caremanager.Birthday = new DateTime(year, month, day); caremanager.Licensed = new DateTime(caremanager.Licensed.Year, 12, 31); if (ModelState.IsValid) { // Uploads Image if (file != null) { BlobHelper.DeleteIfExists("mediafile", caremanager.MediaFileDataId); caremanager.MediaFileDataId = BlobHelper.Upload("mediafile", file, file.FileName); } // Adds / Edits record if (caremanager.CareManagerId == 0) { // Add db.CareManagers.Add(caremanager); var verification = new EmailVerification() { CareManager = caremanager, Email = caremanager.Email }; db.EmailVerifications.Add(verification); db.SaveChanges(); // Notifies CareManager to verify. //SendEmail(caremanager.Email, "[ケアマネ情報局] ケアマネ会員認証", "URL: " + Url.Action("Verify", "EmailVerification", new { verificationCode = verification.VerificationCode}, Request.Url.Scheme)); var added = db.CareManagers.Include(m => m.CareHome).FirstOrDefault(m => m.CareManagerId == caremanager.CareManagerId); dynamic email = new Postal.Email("CareManagerAdded"); email.To = added.Email; email.CareManagerName = added.Name; email.CareHomeName = added.CareHome.Name; email.CareHomeUserName = ""; if (added.CareHome.User != null) { email.CareHomeUserName = added.CareHome.User.Name; } email.VerificationUrl = Url.Action("Verify", "EmailVerification", new { verificationCode = verification.VerificationCode }, Request.Url.Scheme); email.SiteUrl = string.Format("{0}://{1}", Request.Url.Scheme, Request.Url.Authority); email.Send(); } else { // Edit var entry = db.Entry(caremanager); entry.State = EntityState.Unchanged; entry.Property(p => p.Email).IsModified = true; entry.Property(p => p.Name).IsModified = true; entry.Property(p => p.Gender).IsModified = true; entry.Property(p => p.Licensed).IsModified = true; entry.Property(p => p.Birthday).IsModified = true; if (file != null) { entry.Property(p => p.MediaFileDataId).IsModified = true; } db.SaveChanges(); } Log(LogType.CareHome, "所属するケアマネの情報を更新しました。"); return(RedirectToAction("Index")); } ViewBag.Gender = EnumHelper <Gender> .GetSelectList(caremanager.Gender); ViewBag.Year = Helper.Helper.GetBirthdayYears(caremanager.Birthday); ViewBag.Month = Helper.Helper.GetBirthdayMonths(caremanager.Birthday); ViewBag.Day = Helper.Helper.GetBirthdayDays(caremanager.Birthday); ViewBag.Licensed = Helper.Helper.GetLicensedYears(caremanager.Licensed); return(View(caremanager)); }