public ActionResult Edit(int?id, PlayerEdit newItem)
        {
            if (!ModelState.IsValid)
            {
                return(RedirectToAction("edit", new { id = newItem.PlayerId }));
            }

            if (id.GetValueOrDefault() != newItem.PlayerId)
            {
                return(RedirectToAction("Index"));
            }

            var editItem = m.PlayerEdit(newItem);

            if (editItem == null)
            {
                return(RedirectToAction("edit", new { id = newItem.PlayerId }));
            }
            else
            {
                return(RedirectToAction("details", new { id = newItem.PlayerId }));
            }
        }
예제 #2
0
        public PlayerWithDetail PlayerEdit(PlayerEdit newItem)
        {
            var obj = ds.Players.Find(newItem.PlayerId);

            if (obj == null)
            {
                return(null);
            }
            else
            {
                ds.Entry(obj).CurrentValues.SetValues(newItem);

                byte[] photobytes = new byte[newItem.PhotoUpload.ContentLength];
                newItem.PhotoUpload.InputStream.Read(photobytes, 0, newItem.PhotoUpload.ContentLength);

                obj.Photo            = photobytes;
                obj.PhotoContentType = newItem.PhotoUpload.ContentType;

                ds.SaveChanges();

                return(Mapper.Map <PlayerWithDetail>(obj));
            }
        }