Esempio n. 1
0
        public IActionResult CreateAdministrator([FromBody] AdministratorUpsertDto adminDto)
        {
            if (adminDto == null)
            {
                return(BadRequest(ModelState));
            }

            if (administratorRepository.AdminExists(adminDto.UserName))
            {
                ModelState.AddModelError("", "Korisnicko ime vec postoji");
                return(StatusCode(404, ModelState));
            }

            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var obj = mapper.Map <Administrator>(adminDto);

            if (!administratorRepository.CreateAdmin(obj))
            {
                ModelState.AddModelError("", $"Nesto je pogresno u spremanju {obj.UserName}");
                return(StatusCode(500, ModelState));
            }

            return(CreatedAtRoute("GetAdmin", new { id = obj.AdministratorId }, obj));
        }
Esempio n. 2
0
        public IActionResult UpdateAdmin(int id, [FromBody] AdministratorUpsertDto adminDto)
        {
            if (adminDto == null || adminDto.AdministratorId != id)
            {
                return(BadRequest(ModelState));
            }

            var obj = mapper.Map <Administrator>(adminDto);

            if (!administratorRepository.UpdateAdmin(obj))
            {
                ModelState.AddModelError("", $"Nesto je pogresno u spremanju {obj.UserName}");
                return(StatusCode(500, ModelState));
            }

            return(NoContent());
        }