예제 #1
0
        public ActionResult Create([Bind(Include = "UserId,Firstname,Lastname,Email,Password,IsAdmin")] User user)
        {
            if (ModelState.IsValid)
            {
                var u = db.Users.Where(a => a.Email.Equals(user.Email)).FirstOrDefault();
                if (u != null)
                {
                    return(View("../Users/RegisterFailed"));
                }
                else
                {
                    try
                    {
                        db.Users.Add(user);
                        db.SaveChanges();
                        return(View("../Users/RegisterSuccess"));
                    }
                    catch
                    {
                        Console.Write("Bad Input");
                    }
                }
            }

            return(View(user));
        }
예제 #2
0
        public ActionResult Create([Bind(Include = "OrderID,UserID,EventID,PhoneNum,Location,TotalAdult,TotalChild,OrderDate,totalPrice")] Order order)
        {
            if (ModelState.IsValid)
            {
                order.OrderDate = DateTime.Now;
                order.UserID    = Int32.Parse(Session["UserID"].ToString());
                Event event1 = db.Events.Find(order.EventID);
                order.totalPrice = order.TotalAdult * event1.AdultPrice + order.TotalChild * event1.ChildPrice;
                order.Location   = event1.Location;
                db.Orders.Add(order);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }
            //order.OrderDate = DateTime.Now;
            //order.UserID = Int32.Parse(Session["UserID"].ToString());
            //Event event2 = db.Events.Find(order.EventID);
            //order.totalPrice = order.TotalAdult * event2.AdultPrice + order.TotalChild * event2.ChildPrice;
            //order.Location = event2.Location;
            //db.Orders.Add(order);
            //db.SaveChanges();


            ViewBag.EventID = new SelectList(db.Events, "EventID", "EventName", order.EventID);
            ViewBag.UserID  = new SelectList(db.Users, "UserId", "Firstname", order.UserID);
            return(RedirectToAction("Index"));
            //return View(order);
        }
        public ActionResult Create([Bind(Include = "EventID,EventName,EventDescription,EventCategory,StartDate,EndDate,StartTime,EndTime,Location,OpenForRegistration,EventImage,AdultPrice,ChildPrice,CompanyName")] Event @event)
        {
            if (ModelState.IsValid)
            {
                db.Events.Add(@event);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(@event));
        }
        public ActionResult Create([Bind(Include = "EventID,EventName,EventDescription,EventCategory,StartDate,EndDate,StartTime,EndTime,Location,OpenForRegistration,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
            try
            {
                if (ModelState.IsValid)
                {
                    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();
                            db.Events.Add(@event);
                            @event.imagePath = "/images/" + file.FileName;
                            db.SaveChanges();
                        }
                    }
                    // after successfully uploading redirect the user
                    return(RedirectToAction("Index"));
                }
            }
            catch
            {
                Console.Write("Bad Input");
            }

            return(View(@event));
        }
        public ActionResult Create([Bind(Include = "OrderID,UserID,EventID,PhoneNum,Location,TotalAdult,TotalChild,OrderDate,totalPrice")] Order order)
        {
            if (ModelState.IsValid)
            {
                order.OrderDate = DateTime.Now;
                db.Orders.Add(order);
                db.SaveChanges();
                ViewBag.UserID = new SelectList(db.Users, "UserId", "UserId");
                return(RedirectToAction("Index1"));
            }

            ViewBag.EventID = new SelectList(db.Events, "EventID", "EventName", order.EventID);
            ViewBag.UserID  = new SelectList(db.Users, "UserId", "Firstname", order.UserID);
            return(View(order));
        }
        public ActionResult Create([Bind(Include = "UserId,Firstname,Lastname,Email,Password,IsAdmin")] User user)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    db.Users.Add(user);
                    db.SaveChanges();
                    return(RedirectToAction("Index"));
                }
                catch
                {
                    Console.Write("Bad Input");
                }
            }

            return(View(user));
        }
예제 #7
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));
        }
예제 #8
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));
        }