Exemplo n.º 1
0
        public HttpResponseMessage Post(GeofenceGroupModel geofenceGroup)
        {
            if (!ModelState.IsValid)
            {
                return(this.ModelStateResult());
            }

            GeofenceGroup item = Mapper.Map <GeofenceGroup>(geofenceGroup);

            item.UserId = CurrentUser.Id;
            this.repository.Save(item);
            return(Request.CreateResponse(
                       HttpStatusCode.Created, Mapper.Map <GeofenceGroupModel>(item)));
        }
Exemplo n.º 2
0
        public HttpResponseMessage Delete(int id)
        {
            GeofenceGroup item = this.repository.GetById(id);

            if (item != null && item.User.Id == CurrentUser.Id)
            {
                if (item.Geofences.Count == 0)
                {
                    this.repository.Delete(item);
                    return(this.OkResult());
                }
                else
                {
                    return(this.OkResult <object>(new { Success = false }));
                }
            }

            return(Request.CreateResponse(HttpStatusCode.NotFound));
        }
Exemplo n.º 3
0
        public HttpResponseMessage Put(GeofenceGroupModel geofenceGroup, int id)
        {
            if (!ModelState.IsValid)
            {
                return(this.ModelStateResult());
            }

            GeofenceGroup item = this.repository.GetById(id);

            if (item == null || item.User == null || item.User.Id != CurrentUser.Id)
            {
                return(Request.CreateResponse(HttpStatusCode.NotFound));
            }

            item.Name = geofenceGroup.Name;
            this.repository.Save(item);

            return(Request.CreateResponse(
                       HttpStatusCode.Accepted, Mapper.Map <GeofenceGroupModel>(item)));
        }