Пример #1
0
        public ActionResult Create([Bind(Include = "Id,Name,LastName,DNI,Address,Phone,Email")] ClientModel client)
        {
            try
            {
                if (client.Name == null || client.Name == string.Empty)
                {
                    ModelState.AddModelError("Name", "Debe ingresar un nombre");
                }

                if (client.LastName == null || client.LastName == string.Empty)
                {
                    ModelState.AddModelError("LastName", "Debe ingresar un apellido");
                }

                if (client.DNI == 0)
                {
                    ModelState.AddModelError("DNI", "Debe ingresar un DNI");
                }

                if (client.Address == null || client.Address == string.Empty)
                {
                    ModelState.AddModelError("Address", "Debe ingresar una dirección");
                }

                if (client.Phone == null || client.Phone == string.Empty)
                {
                    ModelState.AddModelError("Phone", "Debe ingresar un teléfono");
                }

                if (client.Email == null || client.Email == string.Empty)
                {
                    ModelState.AddModelError("Email", "Debe ingresar un email");
                }


                IEnumerable <Client> rooms = clientBusiness.GetByFilters(ClientModel.FromModel(client));

                if (rooms.ToList().Count > 0)
                {
                    ModelState.AddModelError("Model", "Ya existe un cliente con DNI: " +
                                             client.DNI);
                }


                if (ModelState.IsValid)
                {
                    clientBusiness.Insert(ClientModel.FromModel(client));

                    return(RedirectToAction("Index"));
                }

                return(View(client));
            }
            catch (Exception ex)
            {
                Log.Error(ex.Message, ex);
                return(View());
            }
        }