public JsonResult CreateAsync(ClientView model)
        {
            string msg = "Salvare Client";
            bool   ok  = true;
            //var res = new ClientView();
            var res = new Client();

            try
            {
                if (!_clientRepo.IsUniqueClient(model.Email))
                {
                    ok = false;
                    ModelState.AddModelError("Email", "Email in use");
                }
                else
                {
                    res = _clientRepo.AddClient(model, Convert.ToInt32(Session["Id_User"]), null);
                }
            }
            catch (Exception ex)
            {
                ok  = false;
                msg = ex.Message;
            }

            return(Json(new
            {
                Html = ok ? this.RenderPartialView("_NewRow", res) : "",
                Form = ok ? "" : this.RenderPartialView("_Create", model),
                Success = ok,
                Message = msg
            }));
        }
 public void AddClient(AddEditClient clientFromView, out DefaultError outError)
 {
     if (CheckClient(clientFromView, out outError))
     {
         ClientsRepository.AddClient(SetClientData(clientFromView));
     }
 }
        public JsonResult CreateAsync(ClientView model)
        {
            string msg = "Salvare Client";
            bool   ok  = true;
            var    res = new ClientView();

            try
            {
                //foreach (string inputStringFile in Request.Files)
                //{
                //    HttpPostedFileBase avatar = Request.Files[inputStringFile];
                //throw new Exception("Testing...");
                if (!_clientRepo.IsUniqueClient(model.Email))
                {
                    ok = false;
                    ModelState.AddModelError("Email", "Email in use");
                }
                else
                {
                    res = _clientRepo.AddClient(model, Convert.ToInt32(Session["Id_User"]), null);
                }
                //}
            }
            catch (Exception ex)
            {
                ok  = false;
                msg = ex.Message;
            }

            return(Json(new
            {
                Html = ok ? this.RenderPartialView("_NewRow", res) : "",
                Form = ok ? "" : this.RenderPartialView("_Create", model),
                Success = ok,
                Message = msg
            }));
        }