Ejemplo n.º 1
0
        public IActionResult GetProfile()
        {
            Client client = GetClient();

            if (client == null)
            {
                return(Unauthorized());
            }

            Profile profile = _context.Profiles
                              .SingleOrDefault(c => c.ClientId == client.Id);

            if (profile != null)
            {
                return(Ok(new
                {
                    success = true,
                    data = _mapper.Map <ProfileDTO>(profile)
                }));
            }

            return(Ok(new
            {
                success = false,
                data = new
                {
                    name = "",
                    surname = ""
                }
            }));
        }
Ejemplo n.º 2
0
        public void ModifyProfile(ProfileDTO data)
        {
            Client client = GetClient();

            if (client == null)
            {
                return;
            }

            Profile profile = _context.Profiles
                              .SingleOrDefault(c => c.ClientId == client.Id);

            if (profile == null)
            {
                _context.Profiles.Add(new Profile
                {
                    ClientId = client.Id,
                    Name     = data.Name ?? "",
                    Surname  = data.Surname ?? ""
                });
            }
            else
            {
                if (!string.IsNullOrEmpty(data.Name))
                {
                    profile.Name = data.Name;
                }

                if (!string.IsNullOrEmpty(data.Surname))
                {
                    profile.Surname = data.Surname;
                }
            }

            _context.SaveChanges();
        }
Ejemplo n.º 3
0
 public void Mapping(Profile profile)
 {
     profile.CreateMap <ChargeStation, ChargeStationDto>()
     .ForMember(x => x.Connectors, opt => opt.MapFrom(source => source.Connectors));
 }