Beispiel #1
0
        public int Add(DTOResource dtoResource)
        {
            Resource entityResource = ResourceMapper.GetEntityResource(dtoResource);

            entityResource.Id = UnitOfWork.GetResourceId();

            entityResource.Email = $"{entityResource.Name}.{entityResource.LastName}@reti.it";

            if (dtoResource.LastName.Replace(" ", "").Length >= 5)
            {
                entityResource.Username = dtoResource.LastName.Replace(" ", "").Substring(0, 5).ToLower();
            }
            else
            {
                entityResource.Username = dtoResource.LastName.Replace(" ", "").ToLower();
            }

            if (dtoResource.Name.Replace(" ", "").Length >= 2)
            {
                entityResource.Username += dtoResource.Name.Replace(" ", "").Substring(0, 2).ToLower();
            }
            else
            {
                entityResource.Username += dtoResource.Name.Replace(" ", "").ToLower();
            }

            int ResourceWithSameUsername = UnitOfWork.ResourceRepository.GetAll().Where(res => res.Username.Substring(0, res.Username.Length - 1) == entityResource.Username).Count();

            entityResource.Username += ResourceWithSameUsername + 1;

            UnitOfWork.ResourceRepository.Add(entityResource);
            UnitOfWork.Commit();

            return(entityResource.Id);
        }
Beispiel #2
0
        public static Resource GetEntityResource(DTOResource dtoResource)
        {
            Resource entityResource = new Resource()
            {
                Email    = dtoResource.Email,
                Id       = dtoResource.Id,
                LastName = dtoResource.LastName,
                Name     = dtoResource.Name,
                Username = dtoResource.Username
            };

            return(entityResource);
        }
Beispiel #3
0
        public static DTOResource GetDTOResources(Resource entityResource)
        {
            DTOResource dtoResource = new DTOResource()
            {
                Email    = entityResource.Email,
                Id       = entityResource.Id,
                LastName = entityResource.LastName,
                Name     = entityResource.Name,
                Username = entityResource.Username
            };

            return(dtoResource);
        }
 public IActionResult Add([FromBody] DTOResource dtoResource)
 {
     try
     {
         int newResourceId = resourceManager.Add(dtoResource);
         _logger.LogInformation("Added new Resource", newResourceId);
         return(Ok(newResourceId));
     }
     catch (Exception ex)
     {
         _logger.LogError("Error during Resource/Add", ex.Message);
         resourceManager.Dispose();
         return(StatusCode(500, ex.Message));
     }
 }