Example #1
0
 public HttpResponseMessage Post([FromBody] Category category)
 {
     try
     {
         using (var db = new dbTourismEventAppEntities())
         {
             var entity = db.Category.FirstOrDefault(cat => cat.CategoryID == category.CategoryID);
             if (entity == null)
             {
                 db.Category.Add(category);
                 db.SaveChanges();
                 var response = Request.CreateResponse(HttpStatusCode.Created, category);
                 response.Headers.Location = new Uri(Url.Link("GetCategoryByID", new  { id = category.CategoryID }));
                 return(response);
             }
             else
             {
                 return(Request.CreateErrorResponse(HttpStatusCode.Conflict, "The category name is already exist"));
             }
         }
     }catch (Exception ex)
     {
         return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ex.Message));
     }
 }
Example #2
0
        public HttpResponseMessage Update([FromBody] Category category)
        {
            try
            {
                using (var db = new dbTourismEventAppEntities())
                {
                    var entity = db.Category.FirstOrDefault(cat => cat.CategoryID == category.CategoryID);
                    if (entity != null)
                    {
                        //db.Category.Attach(category);
                        //db.Entry(category).State = System.Data.Entity.EntityState.Modified;
                        entity.CategoryName = category.CategoryName;
                        entity.Description  = category.Description;
                        entity.IsActive     = category.IsActive;
                        entity.IsDeleted    = category.IsDeleted;
                        entity.IsFeatured   = category.IsFeatured;

                        db.SaveChanges();
                        return(Request.CreateResponse(HttpStatusCode.OK, entity));
                    }
                    else
                    {
                        return(Request.CreateErrorResponse(HttpStatusCode.NotFound, "The catagory with id = " + category.CategoryName + " is not found"));
                    }
                }
            }
            catch (Exception ex)
            {
                return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ex.Message));
            }
        }
Example #3
0
 public HttpResponseMessage Post([FromBody] Event entity)
 {
     try
     {
         using (var db = new dbTourismEventAppEntities())
         {
             var evn = db.Event.FirstOrDefault(ev => ev.EventID == entity.EventID);
             if (evn == null)
             {
                 db.Event.Add(entity);
                 db.SaveChanges();
                 var response = Request.CreateResponse(HttpStatusCode.Created, entity);
                 response.Headers.Location = new Uri(Url.Link("GetEventByID", new { id = entity.EventID }));
                 return(response);
             }
             else
             {
                 return(Request.CreateErrorResponse(HttpStatusCode.Conflict, "The event name is already exist"));
             }
         }
     }
     catch (Exception ex)
     {
         return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ex.Message));
     }
 }
Example #4
0
 public HttpResponseMessage GetCategories()
 {
     try
     {
         using (var db = new dbTourismEventAppEntities())
         {
             var response = Request.CreateResponse(HttpStatusCode.OK, db.Category.ToList());
             return(response);
         }
     }catch (Exception ex)
     {
         return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ex.Message));
     }
 }
Example #5
0
 public HttpResponseMessage GetCategories(int?id)
 {
     using (var db = new dbTourismEventAppEntities())
     {
         var entity = db.Category.FirstOrDefault(cat => cat.CategoryID == id);
         if (entity != null)
         {
             return(Request.CreateResponse(HttpStatusCode.OK, entity));
         }
         else
         {
             return(Request.CreateErrorResponse(HttpStatusCode.NotFound, "The catagory with id = " + id + " is not found"));
         }
     }
 }
Example #6
0
 public HttpResponseMessage GetEvent(int?id)
 {
     using (var db = new dbTourismEventAppEntities())
     {
         var entity = db.Event.FirstOrDefault(ev => ev.EventID == id);
         if (entity != null)
         {
             return(Request.CreateResponse(HttpStatusCode.OK, entity));
         }
         else
         {
             return(Request.CreateErrorResponse(HttpStatusCode.NotFound, "The event with id = " + id + " is not found"));
         }
     }
 }
Example #7
0
 public HttpResponseMessage Delete(int?id)
 {
     using (var db = new dbTourismEventAppEntities())
     {
         var entity = db.Category.FirstOrDefault(cat => cat.CategoryID == id);
         if (entity != null)
         {
             db.Entry(entity).State = System.Data.Entity.EntityState.Deleted;
             db.SaveChanges();
             return(Request.CreateResponse(HttpStatusCode.OK, entity));
         }
         else
         {
             return(Request.CreateErrorResponse(HttpStatusCode.NotFound, "The catagory with id = " + id + " is not found"));
         }
     }
 }
Example #8
0
 public HttpResponseMessage Update([FromBody] Event entity)
 {
     try
     {
         using (var db = new dbTourismEventAppEntities())
         {
             var evnt = db.Event.FirstOrDefault(ev => ev.EventID == entity.EventID);
             if (evnt != null)
             {
                 //db.Entry(entity).State = System.Data.Entity.EntityState.Modified;
                 evnt.ImagePath   = entity.ImagePath;
                 evnt.Title       = entity.Title;
                 evnt.Type        = entity.Type;
                 evnt.Description = entity.Description;
                 evnt.StartTime   = entity.StartTime;
                 evnt.EndTime     = entity.EndTime;
                 evnt.Price       = entity.Price;
                 evnt.Rating      = entity.Rating;
                 evnt.IsActive    = entity.IsActive;
                 evnt.IsDeleted   = entity.IsDeleted;
                 evnt.IsFeatured  = entity.IsFeatured;
                 evnt.CategoryID  = entity.CategoryID;
                 db.SaveChanges();
                 return(Request.CreateResponse(HttpStatusCode.OK, entity));
             }
             else
             {
                 return(Request.CreateErrorResponse(HttpStatusCode.NotFound, "The event with id = " + entity.EventID + " is not found"));
             }
         }
     }
     catch (Exception ex)
     {
         return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ex.Message));
     }
 }
 public HttpResponseMessage Update(int?id, [FromBody] Hotel Hotel)
 {
     try
     {
         using (var db = new dbTourismEventAppEntities())
         {
             var entity = db.Hotel.FirstOrDefault(cat => cat.HotelID == id);
             if (entity != null)
             {
                 db.Entry(Hotel).State = System.Data.Entity.EntityState.Modified;
                 db.SaveChanges();
                 return(Request.CreateResponse(HttpStatusCode.OK, entity));
             }
             else
             {
                 return(Request.CreateErrorResponse(HttpStatusCode.NotFound, "The hotel with id = " + id + " is not found"));
             }
         }
     }
     catch (Exception ex)
     {
         return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ex.Message));
     }
 }