public async Task <IActionResult> Put(string id, [FromBody] VerificatorView verificator)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            var ver = await db.Verificators.FirstOrDefaultAsync(v => v.Id == id);

            ver.Address     = verificator.Address;
            ver.Certificate = verificator.Certificate;
            ver.Code        = verificator.Code;
            ver.Director    = verificator.Director;
            ver.Name        = verificator.Name;
            ver.Phone       = verificator.Phone;

            db.Verificators.Update(ver);
            await db.SaveChangesAsync();

            return(Ok(ver));
        }
Exemple #2
0
        public async Task <IActionResult> Put(int id, [FromBody] VerificatorView verificator)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            var ver = await db.Verificators.GetAsync(id);

            ver.Address     = verificator.Address;
            ver.Certificate = verificator.Certificate;
            ver.Code        = verificator.Code;
            ver.Director    = verificator.Director;
            ver.Name        = verificator.Name;
            ver.Phone       = verificator.Phone;

            db.Verificators.Update(ver);
            await db.SaveAsync();

            return(Ok(ver));
        }
        public async Task <IActionResult> Get(string id)
        {
            var verificator = await db.Verificators.FirstOrDefaultAsync(v => v.Id == id);

            if (verificator == null)
            {
                return(NotFound());
            }
            var view = new VerificatorView()
            {
                Id          = id,
                Address     = verificator.Address,
                Certificate = verificator.Certificate,
                Code        = verificator.Code,
                Director    = verificator.Director,
                Name        = verificator.Name,
                Phone       = verificator.Phone
            };

            return(Ok(view));
        }
Exemple #4
0
        public async Task <IActionResult> Post([FromBody] VerificatorView verificator)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            var ver = new Verificator()
            {
                Address     = verificator.Address,
                Certificate = verificator.Certificate,
                Code        = verificator.Code,
                Director    = verificator.Director,
                Name        = verificator.Name,
                Phone       = verificator.Phone
            };
            await db.Verificators.AddAsync(ver);

            await db.SaveAsync();

            return(CreatedAtAction("Get", new { id = ver.Id }, ver));
        }