public ActionResult Edit(int?id, CoachEdit newItem)
        {
            if (!ModelState.IsValid)
            {
                var errors = ModelState.Where(x => x.Value.Errors.Any())
                             .Select(x => new { x.Key, x.Value.Errors });

                return(RedirectToAction("edit", new { id = newItem.CoachId }));
            }

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

            var editItem = m.CoachEdit(newItem);

            if (editItem == null)
            {
                return(RedirectToAction("edit", new { id = newItem.CoachId }));
            }
            else
            {
                return(RedirectToAction("details", new { id = newItem.CoachId }));
            }
        }
Beispiel #2
0
        //Coach Edit
        public CoachWithDetail CoachEdit(CoachEdit newItem)
        {
            var obj = ds.Coaches.Find(newItem.CoachId);

            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;

                obj.CoachProfile = newItem.CoachProfile;

                ds.SaveChanges();

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