public PlayerViewModel(Player player) { this.Id = player.Id; this.LastName = player.LastName; this.FirstName = player.FirstName; this.Patronymic = player.Patronymic; this.Gender = player.Gender; this.Day = player.Birthday.HasValue ? player.Birthday.Value.Day.ToString() : null; this.Month = player.Birthday.HasValue ? player.Birthday.Value.Month.ToString() : null; this.Year = player.Birthday.HasValue ? player.Birthday.Value.Year.ToString() : null; this.ImageName = player.ImageName; }
public ActionResult Create(PlayerViewModel model, int? page, int? count) { ViewBag.Page = page = page.HasValue && page > 1 ? page : 1; ViewBag.Count = count = count.HasValue && count > 1 ? count : __default_count; if (!ModelState.IsValid) return View(model); var player = new Player() { LastName = model.LastName, FirstName = model.FirstName, Patronymic = model.Patronymic, Gender = model.Gender }; DateTime? date = null; if (ParseDate(model.Day, model.Month, model.Year, out date)) { if (date != null) { player.Birthday = date; } } else { ModelState.AddModelError("Year", "Дата рождения заполнена не полностью"); return View(model); } if (model.Image != null) { //сохраняем картинку player.ImageName = new ImageHelper(ImageStoragePath).Upload(model.Image.InputStream); } DataAccess.Players.Add(player); DataAccess.SaveChanges(); return RedirectToAction("index", new { page = page, count = count }); }