public ActionResult Edit(int id) { ViewBag.Title = "Editar Lotes"; LoteViewModels model = new LoteViewModels(); Lotes = dbCtx.Lote.FirstOrDefault(a => a.Id == id); model.Precio = Lotes.Precio; model.MedidaId = Lotes.MedidaId; model.EstadoLoteId = Lotes.EstadoLoteId; model.LotificadoraId = Lotes.LotificadoraId; model.ManzanaId = Lotes.ManzanaId; model.AreaId = Lotes.AreaId; model.Medidas = dbCtx.Medida.ToList(); model.EstadoLote = dbCtx.EstadoLote.ToList(); model.Lotificadora = dbCtx.Lotificadora.ToList(); model.Area = dbCtx.Area.ToList(); model.Manzana = dbCtx.Manzana.ToList(); model.Interes = dbCtx.Interes.ToList(); dbCtx.SaveChanges(); return(View(model)); }
public ActionResult Create() { ViewBag.Title = "Ingresar Lotes"; LoteViewModels model = new LoteViewModels(); model.Medidas = dbCtx.Medida.ToList(); model.EstadoLote = dbCtx.EstadoLote.ToList(); model.Lotificadora = dbCtx.Lotificadora.ToList(); model.Area = dbCtx.Area.ToList(); model.Manzana = dbCtx.Manzana.ToList(); model.Interes = dbCtx.Interes.ToList(); return(View(model)); }
public ActionResult Delete(LoteViewModels model) { var estado = (from p in dbCtx.Lote where p.Id == model.Id select p).FirstOrDefault(); dbCtx.Lote.Remove(estado); int num = dbCtx.SaveChanges(); if (num > 0) { return(new HttpStatusCodeResult(System.Net.HttpStatusCode.OK)); } return(new HttpStatusCodeResult(System.Net.HttpStatusCode.BadRequest)); }
public ActionResult Edit(LoteViewModels model) { if (ModelState.IsValid) { Lotes = dbCtx.Lote.FirstOrDefault(a => a.Id == model.Id); Lotes.Precio = model.Precio; Lotes.MedidaId = model.MedidaId; Lotes.EstadoLoteId = model.EstadoLoteId; Lotes.LotificadoraId = model.LotificadoraId; Lotes.ManzanaId = model.ManzanaId; Lotes.AreaId = model.AreaId; Lotes.InteresId = model.InteresId; dbCtx.SaveChanges(); } return(RedirectToAction("Index")); }
public ActionResult Create(LoteViewModels model) { var validImageTypes = new string[] { "image/gif", "image/jpeg", "image/pjpeg", "image/png", }; if (model.ImageUpload == null || model.ImageUpload.ContentLength == 0) { ModelState.AddModelError("ImageUpload", "Es requerido."); } else if (!validImageTypes.Contains(model.ImageUpload.ContentType)) { ModelState.AddModelError("ImageUpload", "Please choose either a GIF, JPG or PNG image."); } if (ModelState.IsValid) { Lotes.Precio = model.Precio; Lotes.MedidaId = model.MedidaId; //Seleccionamos el estad cliente que sea 'ACTIVO' y luego lo agregamos a FK EstadoClienteId EstadoLote estado = dbCtx.EstadoLote.FirstOrDefault(e => e.NombreEstado == "Disponible"); Lotes.EstadoLoteId = estado.Id; Lotes.LotificadoraId = model.LotificadoraId; Lotes.ManzanaId = model.ManzanaId; Lotes.AreaId = model.AreaId; Lotes.InteresId = model.InteresId; if (model.ImageUpload != null && model.ImageUpload.ContentLength > 0) { //Invertimos el nombre de la imagen y tomamos la extension de esta string extension = Reverse(model.ImageUpload.FileName).Split('.')[0]; extension = Reverse(extension); //invertimos nuevamente la cadena generada en la linea anterior string nameImage; string time = DateTime.UtcNow.ToString(); time = time.Replace("/", "_"); time = time.Replace(" ", "_"); time = time.Replace(":", "_"); time = time.Replace(".", ""); //Le damos un nuevo nombre a la imagen, en base al fecha y hora para que no se repitan urls. nameImage = time + "." + extension; string uploadDir = "../Images/Lotes/"; //Ruta donde se guardara. var imagePath = Path.Combine(Server.MapPath(uploadDir), nameImage); //generamos el path //generamos la url a guardar en la base de datos. var imageUrl = Path.Combine(uploadDir, nameImage); model.ImageUpload.SaveAs(imagePath); //guardamos la imagen. Lotes.ImageUrl = imageUrl; //por ultimo la pasamos la url al modelo para ser guardada en la BD. } dbCtx.Lote.Add(Lotes); dbCtx.SaveChanges(); } return(RedirectToAction("Index")); }