Пример #1
0
        public HttpResponseMessage Update([FromBody] AccountView inst)
        {
            var t = new AccountValidationAttribute();

            if (!(t.IsValid(inst)))
            {
                var resp = Request.CreateErrorResponse(HttpStatusCode.BadRequest, t.ErrorMessage);
                return(resp);
            }
            else
            {
                accountService.Update(inst.AccountFromViewToDomain());
                HttpResponseMessage response = Request.CreateResponse <string>(HttpStatusCode.OK, "Account успешно обновлен!!");
                return(response);
            }
        }
Пример #2
0
        public HttpResponseMessage Get([FromUri] int id)
        {
            var temp = accountService.Get(id).AccountFromDomainToView();
            var t    = new AccountValidationAttribute();

            if (!(t.IsValid(temp)))
            {
                var resp = Request.CreateErrorResponse(HttpStatusCode.NotFound, t.ErrorMessage.ToString());
                return(resp);
            }
            else
            {
                HttpResponseMessage response = Request.CreateResponse <AccountView>(HttpStatusCode.OK, temp);
                return(response);
            }
        }
Пример #3
0
        public HttpResponseMessage Delete([FromUri] int id)
        {
            var temp = accountService.Get(id).AccountFromDomainToView();
            var t    = new AccountValidationAttribute();

            if (!(t.IsValid(temp)))
            {
                var resp = Request.CreateErrorResponse(HttpStatusCode.NotFound, t.ErrorMessage);
                return(resp);
            }
            else
            {
                accountService.Delete(id);
                HttpResponseMessage response = Request.CreateResponse <string>(HttpStatusCode.OK, "Account успешно удален!!");
                return(response);
            }
        }