Exemplo n.º 1
0
 public async Task <IActionResult> Put(int id, [FromBody] coreevent.Event item)
 {
     try
     {
         if (!ModelState.IsValid)
         {
             throw new ArgumentException("ModelState must be invalid", nameof(ModelState));
         }
         if (id != item.Id)
         {
             return(NotFound("Event not found"));
         }
         var np = _eventService.UpdateEvent(item);
         return(Ok(np));
     }
     catch (Exception ex)
     {
         var sb = new System.Text.StringBuilder();
         while (ex != null)
         {
             ModelState.AddModelError("Event:Put", ex.Message);
             ex = ex.InnerException;
         }
         return(BadRequest(ModelState));
     }
 }
Exemplo n.º 2
0
        public coreevent.Event NewEvent(string firstName, string lastName, string address)
        {
            var evt = new coreevent.Event()
            {
                //Name = firstName + " " + lastName,
                //Address = new Address(){ Address1 = address}
            };

            return(evt);
        }
Exemplo n.º 3
0
        public coreevent.Event Create(coreevent.Event evt)
        {
            /*/
             * if (Event.Type != null)
             * {
             *  _ctx.Attach(Event.Type).State = EntityState.Unchanged;
             * }*/
            var EventSaved = _ctx.Events.Add(evt).Entity;

            _ctx.SaveChanges();
            return(EventSaved);
        }
Exemplo n.º 4
0
        public coreevent.Event Update(coreevent.Event EventUpdate)
        {
            if (EventUpdate.Createdate == null || (EventUpdate.Createdate != null && EventUpdate.Createdate.Year == 1))
            {
                EventUpdate.Createdate = System.DateTime.Now;
            }
            _ctx.Attach(EventUpdate).State = EntityState.Modified;

            /*     _ctx.Entry(EventUpdate).Collection(c => c.Orders).IsModified = true;
             *   _ctx.Entry(EventUpdate).Reference(c => c.Type).IsModified = true;
             *   var orders = _ctx.Orders.Where(o => o.Event.Id == EventUpdate.Id
             *                          && !EventUpdate.Orders.Exists(co => co.Id == o.Id));
             *   foreach (var order in orders)
             *   {
             *       order.Event = null;
             *       _ctx.Entry(order).Reference(o => o.Event)
             *           .IsModified = true;
             *   }
             */
            _ctx.SaveChanges();
            return(EventUpdate);
        }
Exemplo n.º 5
0
 public ActionResult <coreevent.Event> Post([FromBody] coreevent.Event value)
 {
     try
     {
         //string authorization = Request.Headers["Authorization"];
         if (!ModelState.IsValid)
         {
             throw new ArgumentException("ModelState must be invalid", nameof(ModelState));
         }
         var np = _eventService.CreateEvent(value);
         return(Ok(np));
     }
     catch (Exception ex)
     {
         var sb = new System.Text.StringBuilder();
         while (ex != null)
         {
             ModelState.AddModelError("Event:Post", ex.Message);
             ex = ex.InnerException;
         }
         return(BadRequest(ModelState));
     }
 }
Exemplo n.º 6
0
 public coreevent.Event UpdateEvent(coreevent.Event evt)
 {
     return(_eventRepo.Update(evt));
 }
Exemplo n.º 7
0
 public coreevent.Event CreateEvent(coreevent.Event evt)
 {
     return(_eventRepo.Create(evt));
 }