예제 #1
0
        public async Task <ActionResult> Edit([Bind(Include = "Id,descripcion,fecha,nombreFichero,foto,UserId")] Coch coch)
        {
            if (ModelState.IsValid)
            {
                db.Entry(coch).State = EntityState.Modified;
                await db.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }
            ViewBag.UserId = new SelectList(db.Users, "Id", "user1", coch.UserId);
            return(View(coch));
        }
예제 #2
0
 public bool Update(DriverDocument obj)
 {
     dc.Entry(obj).State = System.Data.Entity.EntityState.Modified;
     return(dc.SaveChanges() > 0);
 }
예제 #3
0
 public bool Update(PaymentCard obj)
 {
     dc.Entry(obj).State = System.Data.Entity.EntityState.Modified;
     return(dc.SaveChanges() > 0);
 }
예제 #4
0
        public async Task <ActionResult> Edit(int?id, HttpPostedFileBase upload)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            var user = db.Users.Find(id);

            if (TryUpdateModel(user, "", new string[] { "user1", "email", "password", "confirmPassword", "nombreFichero" }))
            {
                try
                {
                    if (upload != null && upload.ContentLength > 0)
                    {
                        if (user.Files.Any(fi => fi.FileType == (int?)FileType.Image))
                        {
                            db.Files.Remove(user.Files.First(fi => fi.FileType == (int?)FileType.Image));
                        }

                        if (user.nombreFichero.Equals(""))
                        {
                            user.nombreFichero = upload.FileName;
                        }
                        var imagen = new Models.File
                        {
                            FileName    = System.IO.Path.GetFileName(upload.FileName),
                            FileType    = (int?)FileType.Image,
                            ContentType = upload.ContentType
                        };
                        using (var reader = new BinaryReader(upload.InputStream))
                        {
                            imagen.Content = reader.ReadBytes(upload.ContentLength);
                            user.foto      = imagen.Content;
                        }
                        user.Files = new List <Models.File> {
                            imagen
                        };
                    }
                    db.Entry(user).State = EntityState.Modified;
                    Debug.WriteLine(user.ToString());
                    await db.SaveChangesAsync();

                    return(RedirectToAction("Index", new { id = user.Id }));
                }
                catch (RetryLimitExceededException /* dex */)
                {
                    //Log the error (uncomment dex variable name and add a line here to write a log.
                    ModelState.AddModelError("No ha sido posible añadir el usuario", " Inténtalo de nuevo, si el problema persisite contacte con el administrador.");
                }
                catch (System.Data.Entity.Infrastructure.DbUpdateException e)
                {
                    ViewBag.ErrorMessage = "Ya existe " + valorDuplicado(e);
                }
                catch (System.Data.Entity.Validation.DbEntityValidationException e)
                {
                    Debug.WriteLine(e.EntityValidationErrors + "***");
                }
            }



            ViewBag.UserId = new SelectList(db.Users, "Id", "user1", id);
            return(View(user));
        }
예제 #5
0
 public bool Update(AuthenticationToken obj)
 {
     dc.Entry(obj).State = System.Data.Entity.EntityState.Modified;
     return(dc.SaveChanges() > 0);
 }