public IActionResult SaveDesire(UserDesire userDesire)
        {
            bool   result    = true;
            string message   = string.Empty;
            var    userEmail = User.GetSpecificClaim("Email");

            if (ModelState.IsValid)
            {
                userDesire.UserModified = userEmail;

                if (userDesire.Id == 0)
                {
                    userDesire.UserCreated = userEmail;
                    _userDesireService.Add(userDesire, out result, out message);
                }
                else
                {
                    _userDesireService.UpdateChangedProperties(userDesire, out result, out message);
                }

                return(new OkObjectResult(new GenericResult(result, message)));
            }
            else
            {
                List <string> listErrors  = ModelState.Values.SelectMany(v => v.Errors).Select(x => x.ErrorMessage).ToList();
                string        errorString = String.Join("\n", listErrors.ToArray());
                return(new OkObjectResult(new GenericResult(false, errorString)));
            }
        }
Esempio n. 2
0
 public void Add(UserDesire userDesire, out bool result, out string message)
 {
     _userDesireRepository.Add(userDesire, out result, out message);
     if (result)
     {
         SaveChanges();
     }
     else
     {
         Dispose();
     }
 }
Esempio n. 3
0
 public void UpdateChangedProperties(UserDesire userDesire, out bool result, out string message)
 {
     _userDesireRepository.UpdateChangedProperties(userDesire.Id, userDesire, out result, out message);
     if (result)
     {
         SaveChanges();
     }
     else
     {
         Dispose();
     }
 }