Beispiel #1
0
        public async Task <IHttpActionResult> Post(EntityAddOrUpdateViewModel model)
        {
            IHttpActionResult res = BadRequest();

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

            var serviceRes = await _entityService.Add(new EntityAddRequest()
            {
                RequestOwner = User,
                ViewModel    = model
            });

            if (serviceRes.Access == ResponseAccess.Granted)
            {
                res = Ok(model);
            }

            if (serviceRes.Access == ResponseAccess.Deny)
            {
                res = Unauthorized(serviceRes.Message);
            }

            return(res);
        }
Beispiel #2
0
        public async Task <IHttpActionResult> Put(string schemeHandle, Guid id, EntityAddOrUpdateViewModel model)
        {
            IHttpActionResult res = BadRequest();

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

            if (id != model.Id)
            {
                return(res);
            }

            var serviceRes = await _entityService.Update(new EntityUpdateRequest()
            {
                RequestOwner = User,
                ViewModel    = model,
                EntityId     = id,
                SchemeHandle = schemeHandle
            });

            if (serviceRes.Access == ResponseAccess.Granted)
            {
                res = Ok(model);
            }

            if (serviceRes.Access == ResponseAccess.Deny)
            {
                res = Unauthorized(serviceRes.Message);
            }

            return(res);
        }
 public static void MapToExisting(this EntityAddOrUpdateViewModel model, Entity entity)
 {
     Mapper.Map(model, entity);
 }
 public static Entity MapToEntity(this EntityAddOrUpdateViewModel model)
 {
     return(Mapper.Map <Entity>(model));
 }