示例#1
0
    public async Task <ActionResult> Post([FromBody] RepresentativeDTO repDto)
    {
        try
        {
            if (repDto == null)
            {
                return(NoContent());
            }

            repDto.Created = DateTime.Now;
            var rep = _mapper.Map <Representative>(repDto);
            _context.Representatives.Add(rep);
            _context.SaveChanges();

            repDto = _mapper.Map <RepresentativeDTO>(rep);
            return(await Task.Run(() => new ObjectResult(repDto)));
        }
        catch
        {
            throw;
        }
    }
示例#2
0
    public async Task <ActionResult> Put(int id, [FromBody] RepresentativeDTO repDto)
    {
        try
        {
            var orgRep = _context.Representatives.Find(id);

            if (id != repDto.Id)
            {
                return(BadRequest());
            }

            if (orgRep == null)
            {
                return(BadRequest());
            }

            // rep.Address = repDto.Address;
            // rep.Continuous = repDto.Continuous;
            // rep.DateOfBirth = repDto.DateOfBirth;
            // rep.Name = repDto.Name;
            // rep.PersonalPhone = repDto.PersonalPhone;
            // rep.Phone = repDto.Phone;
            // rep.Position = repDto.Position;
            // rep.Created = DateTime.Now;
            // rep.UniversalIP = repDto.UniversalIP;
            // rep.Email = repDto.Email;

            orgRep = _mapper.Map(repDto, orgRep);
            _context.SaveChanges();
            return(await Task.Run(() => new ObjectResult(repDto)));
        }
        catch
        {
            throw;
        }
    }