Exemplo n.º 1
0
 public ActionResult Edit([Bind(Include = "UserId,Firstname,Lastname,Email,Password,IsAdmin")] User user)
 {
     if (ModelState.IsValid)
     {
         db.Entry(user).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(user));
 }
 public ActionResult Edit([Bind(Include = "EventID,EventName,EventDescription,EventCategory,StartDate,EndDate,StartTime,EndTime,Location,OpenForRegistration,EventImage,AdultPrice,ChildPrice,CompanyName")] Event @event)
 {
     if (ModelState.IsValid)
     {
         db.Entry(@event).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(@event));
 }
        public ActionResult Edit([Bind(Include = "EventID,EventName,EventDescription,EventCategory,StartDate,EndDate,StartTime,EndTime,Location,OpenForRegistration,imagePath,AdultPrice,ChildPrice,CompanyName")] Event @event, HttpPostedFileBase file)
        {
            #region ViewBag
            ViewBag.MyCatagories = new List <SelectListItem>()
            {
                new SelectListItem {
                    Text = "Conference", Value = "Conference"
                },
                new SelectListItem {
                    Text = "Seminar", Value = "Seminar"
                },
                new SelectListItem {
                    Text = "Presentation", Value = "Presentation"
                },
            };
            #endregion
            if (ModelState.IsValid)
            {
                try
                {
                    db.Entry(@event).State = EntityState.Modified;
                    if (file != null)
                    {
                        string pic  = System.IO.Path.GetFileName(file.FileName);
                        string path = System.IO.Path.Combine(Server.MapPath("/images"), pic);
                        // file is uploaded
                        file.SaveAs(path);

                        // save the image path path to the database or you can send image
                        // directly to database
                        // in-case if you want to store byte[] ie. for DB
                        using (MemoryStream ms = new MemoryStream())
                        {
                            file.InputStream.CopyTo(ms);
                            byte[] array = ms.GetBuffer();
                            @event.imagePath = "/images/" + file.FileName;
                            db.SaveChanges();
                        }
                    }
                    else
                    {
                        @event.imagePath = TempData["oldPath"].ToString();
                        db.SaveChanges();
                    }
                    //db.SaveChanges();
                    return(RedirectToAction("Index"));
                }
                catch
                {
                    Console.WriteLine("Bad Input");
                }
            }
            return(View(@event));
        }
 public ActionResult Edit([Bind(Include = "OrderID,UserID,EventID,PhoneNum,Location,TotalAdult,TotalChild,OrderDate,totalPrice")] Order order)
 {
     if (ModelState.IsValid)
     {
         db.Entry(order).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index", "UserEvents"));
     }
     ViewBag.EventID = new SelectList(db.Events, "EventID", "EventName", order.EventID);
     ViewBag.UserID  = new SelectList(db.Users, "UserId", "Firstname", order.UserID);
     return(View(order));
 }
Exemplo n.º 5
0
        public ActionResult Edit([Bind(Include = "OrderID,UserID,EventID,PhoneNum,Location,TotalAdult,TotalChild,OrderDate,totalPrice")] Order order)
        {
            if (ModelState.IsValid)
            {
                order.UserID    = Int32.Parse(Session["UserID"].ToString());
                order.OrderDate = DateTime.Now;
                Event event1 = db.Events.Find(order.EventID);
                order.totalPrice = order.TotalAdult * event1.AdultPrice + order.TotalChild * event1.ChildPrice;

                db.Entry(order).State = EntityState.Modified;
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }
            ViewBag.EventID = new SelectList(db.Events, "EventID", "EventName", order.EventID);
            ViewBag.UserID  = new SelectList(db.Users, "UserId", "Firstname", order.UserID);
            return(View(order));
        }
Exemplo n.º 6
0
        //[Authentication.BasicAuthentication]
        public IHttpActionResult PutUser(int id, User user, string Username, string token)
        {
            // check token
            bool validationResult = TokenManager.ValidateUserToken(Username, token);

            if (!validationResult)
            {
                return(Unauthorized());
            } //end check token
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != user.UserId)
            {
                return(BadRequest());
            }

            db.Entry(user).State = EntityState.Modified;

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!UserExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(Ok(user));
        }
Exemplo n.º 7
0
        //[Authentication.BasicAuthentication]
        public IHttpActionResult PutEvent(int id, Event @event, string Username, string token)
        {
            bool validationResult = TokenManager.ValidateUserToken(Username, token);

            if (!validationResult)
            {
                return(Unauthorized());
            }

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

            if (id != @event.EventID)
            {
                return(BadRequest());
            }

            db.Entry(@event).State = EntityState.Modified;

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!EventExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(Ok(@event));
        }