public ActionResult <Travel> PostTravel(int uid, Travel travel)
 {
     try
     {
         string date  = DateTime.Now.ToString("yyyyMMdd");
         var    query = from t in travelDb.Travels
                        where t.TravelId.ToString().StartsWith(date)
                        orderby t.TravelId
                        select t;
         if (query.Count() == 0)
         {
             travel.TravelId = System.Convert.ToInt64(date + "0000");
         }
         else
         {
             travel.TravelId = query.First().TravelId + 1;
         }
         travel.Uid = uid;
         travelDb.Travels.Add(travel);
         travelDb.SaveChanges();
     }
     catch (Exception e)
     {
         return(BadRequest(e.InnerException.Message));
     }
     return(NoContent());
 }
Beispiel #2
0
 public ActionResult <Diary> PostDiary(Diary diary)
 {
     try
     {
         string date  = DateTime.Now.ToString("yyyyMMdd");
         var    query = from t in travelDb.Diaries
                        where t.DiaryId.ToString().StartsWith(date)
                        orderby t.DiaryId
                        select t;
         if (query.Count() == 0)
         {
             diary.DiaryId = System.Convert.ToInt64(date + "0000");
         }
         else
         {
             diary.DiaryId = query.First().DiaryId + 1;
         }
         travelDb.Diaries.Add(diary);
         travelDb.SaveChanges();
     }
     catch (Exception e)
     {
         return(BadRequest(e.InnerException.Message));
     }
     return(NoContent());
 }
        public ActionResult Create([Bind(Include = "DepartmentId,Name")] Department department)
        {
            if (ModelState.IsValid)
            {
                db.Departments.Add(department);
                try
                {
                    db.SaveChanges();
                    return(RedirectToAction("Index"));
                }
                catch (Exception ex)
                {
                    if (ex.InnerException != null &&
                        ex.InnerException.InnerException != null &&
                        ex.InnerException.InnerException.Message.Contains("_Index"))
                    {
                        ModelState.AddModelError(string.Empty, "The are the record with the same value");
                    }
                    else
                    {
                        ModelState.AddModelError(string.Empty, ex.Message);
                    }
                }
            }

            return(View(department));
        }
        public IHttpActionResult PutUsers(int id, Users users)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

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

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

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

            return(StatusCode(HttpStatusCode.NoContent));
        }
Beispiel #5
0
 public ActionResult <Route> AddRoute(long travelid, Route route, Site startSite, Site endSite)
 {
     try
     {
         IQueryable <Route> query = travelDb.Routes;
         query = query.Where(t => t.TravelId == travelid).OrderByDescending(c => c.RouteId);
         if (query != null)
         {
             route.RouteId = query.ToList().First().RouteId + 1;
         }
         else
         {
             route.RouteId = travelid * 100 + 1;
         }
         travelDb.Sites.Add(startSite);
         travelDb.Sites.Add(endSite);
         travelDb.Routes.Add(route);
         travelDb.SaveChanges();
     }
     catch (Exception e)
     {
         return(BadRequest(e.InnerException.Message));
     }
     return(route);
 }
        public ActionResult Create(Guider guider)
        {
            if (ModelState.IsValid)
            {
                if (!(guider.File.ContentType == "image/jpeg" || guider.File.ContentType == "image/gif" || guider.File.ContentType == "image/png"))
                {
                    ModelState.AddModelError("CustomError", "File type allowed : jpeg and gif");
                    RedirectToAction("Index");
                }
                else
                {
                    string subPath = "~/UserImages";
                    bool exists = Directory.Exists(Server.MapPath(subPath));
                    if (!exists)
                        Directory.CreateDirectory(Server.MapPath(subPath));

                    var fileName = Path.GetFileName(guider.File.FileName);
                    var path = Path.Combine(Server.MapPath(subPath), fileName);
                    guider.File.SaveAs(path);
                    var pathName = subPath + "/" + Path.GetFileName(guider.File.FileName);
                    guider.img = pathName;
                    db.Guides.Add(guider);
                    db.SaveChanges();
                }

                return RedirectToAction("Index");
            }
            return View(guider);
        }
        public ActionResult Create(Hotel hotel)
        {
            if (ModelState.IsValid)
            {
                if (!(hotel.File.ContentType == "image/jpeg" || hotel.File.ContentType == "image/gif" || hotel.File.ContentType == "image/png"))
                {
                    ModelState.AddModelError("CustomError", "File type allowed : jpeg and gif");
                    RedirectToAction("Index");
                }
                else
                {
                    string subPath = "~/UserImages";
                    bool   exists  = Directory.Exists(Server.MapPath(subPath));
                    if (!exists)
                    {
                        Directory.CreateDirectory(Server.MapPath(subPath));
                    }

                    var fileName = Path.GetFileName(hotel.File.FileName);
                    var path     = Path.Combine(Server.MapPath(subPath), fileName);
                    hotel.File.SaveAs(path);
                    var pathName = subPath + "/" + Path.GetFileName(hotel.File.FileName);
                    hotel.imagesrc = pathName;
                    db.Hotels.Add(hotel);
                    db.SaveChanges();
                }

                return(RedirectToAction("Index"));
            }

            ViewBag.TravelID = new SelectList(db.Travels, "ID", "Name", hotel.TravelID);
            return(View(hotel));
        }
Beispiel #8
0
 public virtual void Add(T entity)
 {
     if (entity == null)
     {
         throw new ArgumentNullException("请提供泛型类别");
     }
     dbset.Add(entity);
     db.SaveChanges();
 }
Beispiel #9
0
        public ActionResult Create([Bind(Include = "ID,name")] Role role)
        {
            if (ModelState.IsValid)
            {
                db.Roles.Add(role);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(role));
        }
        public ActionResult Create([Bind(Include = "id,createdAt,updatedAt,version,deleted,idKorisnika,idPutovanja")] RezervisanaPutovanjaAzure rezervisanaPutovanjaAzure)
        {
            if (ModelState.IsValid)
            {
                db.RezervisanaPutovanjaAzures.Add(rezervisanaPutovanjaAzure);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(rezervisanaPutovanjaAzure));
        }
        public ActionResult Create([Bind(Include = "id,createdAt,updatedAt,version,deleted,ime,slika,maxKapacitet,kapacitet,idDestinacije,cijena")] HotelAzure hotelAzure)
        {
            if (ModelState.IsValid)
            {
                db.HotelAzures.Add(hotelAzure);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(hotelAzure));
        }
        public ActionResult Create([Bind(Include = "id,createdAt,updatedAt,version,deleted,datumPolaska,datumPovratka,minBrojPutnika,maxBrojPutnika,opisPutovanja,istaknuto,idAgencije,idDestinacije,idHotela,idPrevoz,cijena")] PutovanjeAzure putovanjeAzure)
        {
            if (ModelState.IsValid)
            {
                db.PutovanjeAzures.Add(putovanjeAzure);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(putovanjeAzure));
        }
        public void Post([FromBody] Review review)
        {
            _db.Reviews.Add(review);
            Console.WriteLine("review added");
            var thisDestination = _db.Destinations
                                  .Include(destination => destination.Reviews)
                                  .FirstOrDefault(x => x.DestinationId == review.DestinationId);

            thisDestination.GetAvgRating();
            _db.SaveChanges();
        }
        public ActionResult Create([Bind(Include = "ID,price,startDate,endDate,detail,TravelID")] TravelPlan travelPlan)
        {
            if (ModelState.IsValid)
            {
                db.Plans.Add(travelPlan);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(travelPlan));
        }
        public ActionResult Create([Bind(Include = "id,createdAt,updatedAt,version,deleted,naziv,drzava,kontinent,slika")] DestinacijaAzure destinacijaAzure)
        {
            if (ModelState.IsValid)
            {
                db.DestinacijaAzures.Add(destinacijaAzure);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(destinacijaAzure));
        }
Beispiel #16
0
        public ActionResult Create([Bind(Include = "id,createdAt,updatedAt,version,deleted,vrstaKartice,datumIsteka,broj,csc")] KarticaAzure karticaAzure)
        {
            if (ModelState.IsValid)
            {
                db.KarticaAzures.Add(karticaAzure);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(karticaAzure));
        }
        public ActionResult Create([Bind(Include = "id,createdAt,updatedAt,version,deleted,naziv,idKartica,telefon,grad,lokacija,sifra,email")] AgencijaAzure agencijaAzure)
        {
            if (ModelState.IsValid)
            {
                db.AgencijaAzures.Add(agencijaAzure);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(agencijaAzure));
        }
Beispiel #18
0
        public ActionResult Create([Bind(Include = "id,createdAt,updatedAt,version,deleted,ime,vrstaPrevoza,maxKapacitet,kapacitet,cijena,idDestinacije")] PrevozAzure prevozAzure)
        {
            if (ModelState.IsValid)
            {
                db.PrevozAzures.Add(prevozAzure);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(prevozAzure));
        }
Beispiel #19
0
        public ActionResult Create([Bind(Include = "Id,Name,Age,PassportNo,DateDeparture,DateArrival,FromAirport,ToAirport,Comfort")] Travel travel)
        {
            if (ModelState.IsValid && (travel.DateDeparture < travel.DateArrival))
            {
                db.Travels.Add(travel);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(travel));
        }
        public ActionResult Create([Bind(Include = "TravelTypeID,Name")] TravelType travelType)
        {
            if (ModelState.IsValid)
            {
                db.TravelTypes.Add(travelType);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(travelType));
        }
Beispiel #21
0
        public ActionResult Create([Bind(Include = "userID,userName,password,firstName,lastName,email,phone,regNo,gender,birthDate,roleID")] User user)
        {
            if (ModelState.IsValid)
            {
                db.Users.Add(user);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.roleID = new SelectList(db.Roles, "ID", "name", user.roleID);
            return(View(user));
        }
Beispiel #22
0
        public ActionResult Create(Day dayy)
        {
            if (ModelState.IsValid)
            {
                db.Days.Add(dayy);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.travelPlanID = new SelectList(db.Plans, "ID", "detail", dayy.travelPlanID);
            return(View(dayy));
        }
Beispiel #23
0
        public ActionResult Create([Bind(Include = "imageID,source,TravelID")] Image image)
        {
            if (ModelState.IsValid)
            {
                db.Images.Add(image);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.TravelID = new SelectList(db.Travels, "ID", "Name", image.TravelID);
            return(View(image));
        }
        public ActionResult Create([Bind(Include = "ID,Name,StartFrom,EndTo,TravelTypeID,guiderID")] Travel travel)
        {
            if (ModelState.IsValid)
            {
                db.Travels.Add(travel);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.guiderID     = new SelectList(db.Guides, "ID", "firstName", travel.guiderID);
            ViewBag.TravelTypeID = new SelectList(db.TravelTypes, "TravelTypeID", "Name", travel.TravelTypeID);
            return(View(travel));
        }
Beispiel #25
0
        public ActionResult Create([Bind(Include = "Id,PlaceId,Title,ShortDescription,Text,Status,ImageName")] Place place)
        {
            if (ModelState.IsValid)
            {
                place.PlaceId = place.PlaceId == 0 ? null : place.PlaceId;
                db.Places.Add(place);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.Placelist = TravelClass.DropDown.PlaceIdTitles();
            ViewBag.PlaceId   = new SelectList(TravelClass.DropDown.PlaceIdTitles(), "Id", "Title", place.PlaceId);
            return(View(place));
        }
        public IActionResult Register(RegisterViewModel model, string state)
        {
            var checkEmail = _dbcontext.Users.SingleOrDefault(e => e.Email == model.Email);

            if (ModelState.IsValid)
            {
                if (checkEmail != null)
                {
                    TempData["error"] = "Email already in use";
                    return(View("Login"));
                }

                User NewUser = new User
                {
                    FirstName = model.FirstName,
                    LastName  = model.LastName,
                    Nickname  = model.Nickname,
                    Email     = model.Email,
                    Password  = model.Password
                };
                PasswordHasher <User> Hasher = new PasswordHasher <User>();
                NewUser.Password = Hasher.HashPassword(NewUser, NewUser.Password);
                _dbcontext.Users.Add(NewUser);
                _dbcontext.SaveChanges();

                HttpContext.Session.SetInt32("CurrentUserID", NewUser.Userid);
                return(RedirectToAction("Index"));
            }
            return(View("Login"));
        }
        public ActionResult Create([Bind(Include = "CityId,Name,DepartmentId")] City city)
        {
            if (ModelState.IsValid)
            {
                db.Cities.Add(city);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.DepartmentId = new SelectList(
                CombosHelper.GetDepartments(),
                "DepartmentId",
                "Name",
                city.DepartmentId);
            return(View(city));
        }
        public ActionResult Create([Bind(Include = "id,ime,prezime,jmbg,datumRodjenja,telefon,email,sifra,idKartice")] KorisnikAzure korisnikAzure)
        {//id,createdAt,updatedAt,version,deleted,
            var    zaId = db.KorisnikAzures.ToList();
            String id   = zaId.Count.ToString();

            korisnikAzure.id = id;


            if (ModelState.IsValid)
            {
                db.KorisnikAzures.Add(korisnikAzure);
                db.SaveChanges();

                return(RedirectToAction("Index", "Home"));
            }


            return(View(korisnikAzure));
        }
Beispiel #29
0
        public ActionResult Comment()
        {
            Comment comment = new Comment();

            string commentMessage = Request.Form["comment"];
            string travelPlanID   = Request.Form["travelPlanId"];
            string travellID      = Request.Form["travelId"];

            comment.createdDate = DateTime.Now;
            comment.detail      = commentMessage;
            comment.TravelID    = Convert.ToInt32(travellID);
            User user = db.Users.Where(o => o.email == HttpContext.User.Identity.Name).ToList()[0];

            comment.user   = user;
            comment.userID = user.userID;
            db.Comments.Add(comment);
            db.SaveChanges();
            return(RedirectToAction("TravelDetail", new { id = travelPlanID }));
        }
Beispiel #30
0
 public ActionResult <User> AddUser(User user)
 {
     try{
         IQueryable <User> query = travelDb.Users.OrderByDescending(c => c.Uid);
         if (query != null)
         {
             user.Uid = query.ToList().First().Uid + 1;
         }
         else
         {
             user.Uid = 000000;
         }
         travelDb.Users.Add(user);
         travelDb.SaveChanges();
     }
     catch (Exception e)
     {
         return(BadRequest(e.InnerException.Message));
     }
     return(user);
 }