示例#1
0
        public IActionResult InsertOrUpdateInstitutionContactCharge(InstitutionContactCharge institutionContactCharge)
        {
            if (ModelState.IsValid)
            {
                Action action = Action.None;
                if (institutionContactCharge.Id == 0)
                {
                    action = Action.Create;
                    _unitWork.InstitutionContactCharge.Add(institutionContactCharge);
                }
                else
                {
                    action = Action.Update;
                    _unitWork.InstitutionContactCharge.Update(institutionContactCharge);
                }
                try
                {
                    _unitWork.Save();
                    if (action == Action.Create)
                    {
                        _notyfService.Success("Cargo contacto institución creado correctamente.");
                    }
                    if (action == Action.Update)
                    {
                        _notyfService.Success("Cargo contacto institución actualizado correctamente.");
                    }
                    return(RedirectToAction(nameof(Index)));
                }
                catch (DbUpdateException dbUpdateException)
                {
                    if (dbUpdateException.InnerException.Message.Contains("IX_InstitutionContactCharges_Name"))
                    {
                        _notyfService.Error("Ya existe un cargo contacto institución con el mismo nombre.");

                        return(View(institutionContactCharge));
                    }
                    else
                    {
                        ModelState.AddModelError(string.Empty, dbUpdateException.InnerException.Message);
                    }
                }
                catch (Exception exception)
                {
                    ModelState.AddModelError(string.Empty, exception.Message);
                }
            }
            return(View(institutionContactCharge));
        }
示例#2
0
        public IActionResult InsertOrUpdateInstitutionContactCharge(int?id)
        {
            InstitutionContactCharge institutionContactCharge = new InstitutionContactCharge();

            if (id == null)
            {
                institutionContactCharge.Active = true;
                // Crea un nuevo registro
                return(View(institutionContactCharge));
            }
            // Actualiza el registro
            institutionContactCharge = _unitWork.InstitutionContactCharge.Get(id.GetValueOrDefault());
            if (institutionContactCharge == null)
            {
                return(NotFound());
            }
            return(View(institutionContactCharge));
        }