Ejemplo n.º 1
0
        public ActionResult Create(Cliente cliente, string confirmacion, bool estado, int? COD_COMUNAFK)
        {
            tipusu();
            int tipousuari = tipousuario();
            if (tipousuari == 2)
            {
                string nombre = this.User.Identity.Name.ToString();
                var qwe = from a in db.Usuario
                          where (a.NOMBRE == nombre)
                          select a.ID;
                cliente.IDUSUARIO = qwe.First().ToString();
            }

            var por = from a in db.Cliente
                      where (a.CORREO == cliente.CORREO && a.EMPRESA == cliente.EMPRESA)
                      select a.ID;

            if (por.Count() != 0 || cliente.CORREO != confirmacion)
            {
                ViewBag.texto = "EL CORREO O EL NOMBRE DE LA EMPRESA YA ESTA REGISTRADO POR OTRA PERSONA";
                return Redirect("Create");
            }
            else
            {
                if (estado == false)
                {
                    cliente.CORREOSINO = false;
                }
                else
                {
                    cliente.CORREOSINO = true;
                }

                if (ModelState.IsValid)
                {
                    db.Cliente.Add(cliente);

                    db.SaveChanges();
                    if (COD_COMUNAFK != null)
                    {
                        Despacho despacho = new Despacho();
                        despacho.IDCLIENTE = cliente.ID;
                        despacho.NOMBRE = "CASA CENTRAL";
                        despacho.COD_COMUNAFK = COD_COMUNAFK;
                        despacho.DIRECCION = cliente.DIRECCION;
                        db.Despacho.Add(despacho);
                        db.SaveChanges();
                    }

                    return RedirectToAction("Index");
                }
                ViewBag.IDUSUARIO = new SelectList(db.Usuario, "ID", "NOMBRE", cliente.IDUSUARIO);
                return View(cliente);
            }
        }
Ejemplo n.º 2
0
 public ActionResult Edit(Cliente cliente , bool estado)
 {
     if (estado == false)
     {
         cliente.CORREOSINO = false;
     }
     else
     {
         cliente.CORREOSINO = true;
     }
     if (ModelState.IsValid)
     {
         db.Entry(cliente).State = EntityState.Modified;
         db.SaveChanges();
         return RedirectToAction("Index");
     }
     ViewBag.IDUSUARIO = new SelectList(db.Usuario, "ID", "NOMBRE", cliente.IDUSUARIO);
     return View(cliente);
 }