Exemplo n.º 1
0
        public async Task <ActionResult <Logistician> > PostLogistician([FromBody] Logistician logistician)
        {
            if (logistician == null)
            {
                return(BadRequest());
            }

            _context.Logisticians.Add(logistician);
            await _context.SaveChangesAsync();

            return(CreatedAtAction("GetLogistician", new { id = logistician.Id }, logistician));
        }
Exemplo n.º 2
0
        public async Task <ActionResult <Client> > PatchLogistician(int id, [FromBody] Logistician logistician)
        {
            if (logistician == null || id != logistician.Id)
            {
                return(BadRequest());
            }
            if (!LogisticianExists(id))
            {
                return(NotFound());
            }

            Logistician x = await _context.Logisticians
                            .Include(l => l.RegData)
                            .FirstOrDefaultAsync <Logistician>(x => x.Id == id);

            if (logistician.RegData != null)
            {
                if (logistician.RegData.Name != null)
                {
                    x.RegData.Name = logistician.RegData.Name;
                }
                if (logistician.RegData.Password != null)
                {
                    x.RegData.Password = logistician.RegData.Password;
                }
            }
            if (logistician.CompanyId > 0)
            {
                x.CompanyId = logistician.CompanyId;
            }

            _context.Entry(x).State = EntityState.Modified;
            await _context.SaveChangesAsync();

            return(Ok(logistician));
        }