Exemplo n.º 1
0
        public async Task <IActionResult> Post([FromBody] EditEventDTO model)
        {
            String userName = User.FindFirst(ClaimTypes.NameIdentifier).Value;
            Event  _event   = AutoMapper.Mapper.Map <Event>(model);
            var    user     = await _userManager.FindByNameAsync(userName);

            if (user == null)
            {
                var result = new
                {
                    status  = "error",
                    code    = "1000",
                    message = "User with name " + userName + " is not exist!"
                };
                var error = JsonConvert.SerializeObject(result, _serializerSettings);
                return(new OkObjectResult(error));
            }
            var status = await _eventService.UpdateEvent(_event, user);

            if (!status)
            {
                return(new StatusCodeResult(500));
            }
            var _data    = AutoMapper.Mapper.Map <EventDTO>(_event);
            var response = new
            {
                status  = "success",
                code    = "200",
                message = "Ok",
                data    = _data
            };
            var json = JsonConvert.SerializeObject(response, _serializerSettings);

            return(new OkObjectResult(json));
        }
Exemplo n.º 2
0
        //Edit event
        //Input: EditEventDTO
        //Output: boolean result if the operation is successful
        public static bool EditEvent(EditEventDTO eventToEdit)
        {
            SwapDbConnection db      = new SwapDbConnection();
            Event            myEvent = db.Events.FirstOrDefault(e => e.place_id == eventToEdit.place_id);

            if (myEvent == null)
            {
                return(false);
            }
            myEvent.price      = eventToEdit.price;
            myEvent.place.name = eventToEdit.name;
            db.SaveChanges();
            return(true);
        }
Exemplo n.º 3
0
 public HttpResponseMessage EditEvent(EditEventDTO eventToEdit)
 {
     try
     {
         if (eventToEdit.name == null || eventToEdit.place_id == null)
         {
             return(Request.CreateResponse(HttpStatusCode.BadRequest, "Illegal parameters"));
         }
         bool result = AdminService.EditEvent(eventToEdit);
         if (!result)
         {
             return(Request.CreateResponse(HttpStatusCode.NotFound, "Event not found"));
         }
         return(Request.CreateResponse(HttpStatusCode.OK, result));
     }
     catch (Exception e)
     {
         return(Request.CreateResponse(HttpStatusCode.InternalServerError, "There was an InternalServerError: " + e));
     }
 }