public ActionResult Create(CobroAlquilerModel collection) { try { //if (ModelState.IsValid) //{ var pagoentity = new PagoAlquiler(); pagoentity.ContratoId = int.Parse(collection.Contrato.sIdContrato); pagoentity.FechaPago = DateTime.Now; pagoentity.InquilinoId = int.Parse(collection.Contrato.sInquilinoId); pagoentity.PropiedadId = int.Parse(collection.Contrato.sPropiedadId); pagoentity.Observaciones = collection.Pago.Observaciones; pagoentity.Periodo = DateTime.Parse(collection.sPeriodo.Substring(6, 2) + "/" + collection.sPeriodo.Substring(4, 2) + "/" + collection.sPeriodo.Substring(0, 4)); pagoentity.Observaciones = collection.Pago.Observaciones; var detallePago = new PagoAlquiler_Detalle(); detallePago.Monto = collection.Pago.MontoTotal.Value; detallePago.TipoId = 6; detallePago.PeriodoPago = pagoentity.Periodo.Value; pagoentity.DetallePago = new List <PagoAlquiler_Detalle>(); pagoentity.DetallePago.Add(detallePago); foreach (var item in collection.OtrosPagos) { if (!string.IsNullOrEmpty(item.Monto)) { pagoentity.DetallePago.Add(new PagoAlquiler_Detalle() { TipoId = item.Codigo, Monto = decimal.Parse(item.Monto), PeriodoPago = pagoentity.Periodo.Value }); collection.Pago.MontoTotal += decimal.Parse(item.Monto); } } pagoentity.MontoTotal = collection.Pago.MontoTotal; var pagoBll = new CobrosBLL(); int cod = pagoBll.Add(pagoentity); collection.Pago = pagoentity; collection.Pago.PagoId = cod; string impu = collection.ImpuestosPresentados; ViewBag.Imprimir = true; ViewBag.TipoMsj = "Success"; ViewBag.Message = "El cobro se registro con Exito!!!"; return(View(collection)); //} //else //{ // ViewBag.TipoMsj = "Info"; // ViewBag.Message = string.Join("; ", ModelState.Values // .SelectMany(x => x.Errors) // .Select(x => x.ErrorMessage)); // return View(collection); //} } catch (Exception ex) { ViewBag.TipoMsj = "Error"; ViewBag.Message = ex.Message; return(View()); } }