public async Task <IActionResult> Create(SocialWorkEntity socialWorkEntity)
        {
            if (ModelState.IsValid)
            {
                _context.Add(socialWorkEntity);
                try
                {
                    socialWorkEntity.DischargeDate = DateTime.Now;
                    //socialWorkEntity.User
                    socialWorkEntity.Active = true;
                    await _context.SaveChangesAsync();

                    return(RedirectToAction(nameof(Index)));
                }
                catch (Exception ex)
                {
                    if (ex.InnerException.Message.Contains("duplicate"))
                    {
                        ModelState.AddModelError(string.Empty, "Esta Obra Social ya existe");
                    }
                    else
                    {
                        ModelState.AddModelError(string.Empty, ex.InnerException.Message);
                    }
                }
            }
            return(View(socialWorkEntity));
        }
        public async Task <IActionResult> Edit(int id, SocialWorkEntity socialWorkEntity)
        {
            if (id != socialWorkEntity.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    socialWorkEntity.DischargeDate = DateTime.Now;
                    //socialWorkEntity.User
                    _context.Update(socialWorkEntity);
                    await _context.SaveChangesAsync();

                    return(RedirectToAction(nameof(Index)));
                }
                catch (Exception ex)
                {
                    if (ex.InnerException.Message.Contains("duplicate"))
                    {
                        ModelState.AddModelError(string.Empty, "Esta Obra Social ya existe");
                    }
                    else
                    {
                        ModelState.AddModelError(string.Empty, ex.InnerException.Message);
                    }

                    return(RedirectToAction(nameof(Index)));
                }
            }
            return(View(socialWorkEntity));
        }
Exemple #3
0
 public SocialWorkResponse ToSocialWorkResponse(SocialWorkEntity socialWork)
 {
     return(new SocialWorkResponse
     {
         Id = socialWork.Id,
         Name = socialWork.Name,
         Active = socialWork.Active,
     });
 }