Ejemplo n.º 1
0
 public void SaveResort(Resort resort)
 {
     if (resort.Id == 0)
     {
         Db.Resorts.Add(resort);
     }
     else
     {
         Resort dbEntry = Db.Resorts.Find(resort.Id);
         if (dbEntry != null)
         {
             dbEntry.Name = resort.Name;
             dbEntry.Description = resort.Description;
             dbEntry.PhotoData = resort.PhotoData;
             dbEntry.PhotoMimeType = resort.PhotoMimeType;
         }
     }
     Db.SaveChanges();
 }
 public ActionResult EditResort(Resort resort, HttpPostedFileBase uploadImage)
 {
     if (ModelState.IsValid && uploadImage != null)
     {
         byte[] imageData;
         using (var binaryReader = new BinaryReader(uploadImage.InputStream))
         {
             imageData = binaryReader.ReadBytes(uploadImage.ContentLength);
         }
         resort.PhotoData = imageData;
         repository.SaveResort(resort);
         TempData["message"] = string.Format("{0} has been saved", resort.Id);
         return RedirectToAction("ResortList");
     }
     else
     {
         return View(resort);
     }
 }
Ejemplo n.º 3
0
        public static void ReadBuildResort()
        {
            int counter = 1;
            string line;
            System.IO.StreamReader file = new System.IO.StreamReader(@"rca.csv");
            while ((line = file.ReadLine()) != null)
            {
                System.Console.WriteLine(line);
                string[] array;
                string[] separator = { "," };
                if (counter > 0)
                {
                    int uid = Idcount + counter-1;
                    array = line.Split(separator, StringSplitOptions.None);
                    Name[uid] = array[0];
                    resorts[counter] = new Resort();
                    resorts[counter].id=uid;
                    resorts[counter].name = array[0];
                    double t=0;
                    if (array[1] == "半天")
                    {
                        t = 0.5;
                        resorts[counter].deftime = TimeSpan.FromHours(t * 8);

                    }
                    if (array[1] == "一天")
                    {
                        t = 1;
                        resorts[counter].deftime = TimeSpan.FromHours(t * 8);

                    }
                    resorts[counter].test = resorts[counter].deftime;
                    if (array[1] == "两天")
                    {
                        t = 2;
                        resorts[counter].deftime = TimeSpan.FromHours(t * 8);
                        t = 1;
                        resorts[counter].test = TimeSpan.FromHours(t * 8);
                    }

                    if (array[2] != "")
                    {
                        resorts[counter].CityNear.Add(cities[Array.LastIndexOf(Name, array[2])]);
                        double i = 0;
                        double.TryParse(array[3], out i);
                        {
                            i = 2;
                        }
                        resorts[counter].CityNearTime.Add(TimeSpan.FromHours(i));
                    }
                    if (array[4] != "")
                    {
                        resorts[counter].CityNear.Add(cities[Array.LastIndexOf(Name, array[4])]);
                        double i = 0;
                        if (double.TryParse(array[5], out i))
                        {
                            {
                                i = 2;
                            }
                            resorts[counter].CityNearTime.Add(TimeSpan.FromHours(i ));
                        }
                    }
                    if (array[6] != "")
                    {
                        resorts[counter].CityNear.Add(cities[Array.LastIndexOf(Name, array[6])]);
                        double i = 0;
                        if (double.TryParse(array[7], out i))
                        {
                            if (i > 2)
                            {
                                i = 2;
                            }
                            resorts[counter].CityNearTime.Add(TimeSpan.FromHours(i));
                        }
                    }

                }
                counter++;
            }
            file.Close();
        }