public ActionResult Edit(int id, Clients item, IFormCollection form) { try { //Comboboxes LicenceTypes licenceTypes = new LicenceTypes(); var licenceType = form["licenceType"]; List <SelectListItem> comboTiposLicencia = licenceTypes.GetList(licenceType); ViewBag.ComboTiposLicencia = comboTiposLicencia; ViewBag.licenceType = licenceType; Packages packages = new Packages(); int package = Convert.ToInt32(form["package"]); List <SelectListItem> comboPackages = packages.GetList(package); ViewBag.ComboPackages = comboPackages; ViewBag.package = package; //Validations if ((licenceType == "P" || licenceType == "T") && (!item.DueDate.HasValue)) { throw new Exception("Las licencias 'Paid' o 'Trial' requieren fecha de vencimiento"); } if (licenceType == "F" && item.DueDate.HasValue) { item.DueDate = null; } //Client Update sqlcmd = $@"update public.administration_client set phone = '{item.Phone}' ,address = '{item.Address}' ,valid_client = {item.ValidClient} ,add_date = {pgSQL.DateToSQL(item.AddDate)} ,due_date = {pgSQL.DateToSQL(item.DueDate)} ,renew_date = {pgSQL.DateToSQL(item.RenewalDate)} ,licence_type = '{licenceType}' ,year_payment = {item.YearPayment} ,package_id = {package} ,db_schema = '{item.DbSchema.ToLower()}' ,db_name = '{item.DbName.ToLower()}' where id = {item.Id};"; using (var cnn = pgSQL.GetConnection()) using (var cmd = new NpgsqlCommand(sqlcmd, cnn)) { cmd.CommandType = System.Data.CommandType.Text; cmd.ExecuteNonQuery(); } //Audit information sqlcmd = $@"insert into public.administration_historyclient (date, description, client_id) values({pgSQL.DateToSQL(DateTime.Now.Date)} ,'Edición manual de datos por el operador <{User.Identity.Name}>: valid_client <{item.ValidClient}>, licence_type <{licenceType}>, package_id <{package}>, due_date <{item.DueDate}>, renew_date <{item.RenewalDate}>' ,{item.Id});"; using (var cnn = pgSQL.GetConnection()) using (var cmd = new NpgsqlCommand(sqlcmd, cnn)) { cmd.CommandType = System.Data.CommandType.Text; cmd.ExecuteNonQuery(); } return(RedirectToAction(nameof(Index))); } catch (Exception ex) { string error = $"Error: {ex.Message.ToString()}"; ViewBag.Error = error; return(View(item)); } }