Esempio n. 1
0
        public ActionResult Create(DogsCreateRequest model)
        {
            if (!ModelState.IsValid)
            {
                return(View("Create", model));
            }

            if (model.ImageUpload != null && model.ImageUpload.ContentLength > 0)
            {
                string fileName  = Path.GetFileNameWithoutExtension(model.ImageUpload.FileName);
                string extension = Path.GetExtension(model.ImageUpload.FileName);
                fileName    = fileName + extension;
                model.Image = "~/Image/" + fileName;
                fileName    = Path.Combine(Server.MapPath("~/Image/"), fileName);
                model.ImageUpload.SaveAs(fileName);
            }

            if (model.ImageUpload == null || model.ImageUpload.ContentLength == 0)
            {
                model.Image = "~/Image/image-not-found.png";
            }


            DogService ds = new DogService();

            ds.Create(model);
            return(RedirectToAction("DogsIndex"));
        }
Esempio n. 2
0
        static void Main(string[] args)
        {
            var pluto     = new DogBuilder();
            var chelsea   = new DogBuilder();
            var rinTinTin = new DogBuilder();
            var lazie     = new DogBuilder();
            var rex       = new DogBuilder();


            pluto.WithName("Pluto").WithBreed(new DogBreed("Rotweiler")).WithAge(1);
            chelsea.WithName("Chelsea").WithBreed(new DogBreed("Boxer")).WithAge(2);
            rinTinTin.WithName("RintTinTin").WithBreed(new DogBreed("GermanShepherd")).WithAge(5).InDogHouse();
            lazie.WithName("Lazie").WithBreed(new DogBreed("Chihuahua")).WithAge(1).InDogHouse();
            rex.WithName("Rex").WithBreed(new DogBreed("GermanShepherd")).WithAge(4).InDogHouse();



            var dogService = new DogService(new RefactorDogMockRepository(), new TicketService());

            Console.WriteLine(dogService.DepositDog(DogMapper.MapDogToDto(chelsea), "Amalfi"));
            Console.WriteLine(dogService.AdoptDog(DogMapper.MapDogBreedToDto(new DogBreed("Chihuahua")), "Amalfi"));

            Console.WriteLine(dogService.DepositDog(DogMapper.MapDogToDto(pluto), "Georgina"));
            Console.WriteLine(dogService.AdoptDog(DogMapper.MapDogBreedToDto(new DogBreed("GermanShepherd")), "Georgina"));

            Console.WriteLine(dogService.AdoptDog(DogMapper.MapDogBreedToDto(new DogBreed("GermanShepherd")), "Pau"));

            Console.WriteLine(dogService.AdoptDog(DogMapper.MapDogBreedToDto(new DogBreed("Boxer")), "Dog killer Pshyco"));


            Console.Read();
        }
Esempio n. 3
0
        public ActionResult Edit(int id)
        {
            using (var ctx = new ApplicationDbContext())
            {
                ViewBag.ShelterList = ctx.Shelters.Select
                                          (s => new SelectListItem()
                {
                    Text  = s.ShelterName,
                    Value = s.ShelterId.ToString()
                }
                                          ).ToList();
            }
            var service = new DogService();
            var detail  = service.GetDogById(id);
            var model   =
                new DogEdit
            {
                DogId     = detail.DogId,
                DogName   = detail.DogName,
                DogBreed  = detail.DogBreed,
                DogSex    = detail.DogSex,
                DogWeight = detail.DogWeight,
                DogAge    = detail.DogAge,
                DogPrice  = detail.DogPrice,
                DogImage  = detail.DogImage,
                ShelterId = detail.ShelterId
            };

            return(View(model));
        }
Esempio n. 4
0
        public ActionResult Delete(int id)
        {
            DogService ds = new DogService();

            ds.Delete(id);
            return(RedirectToAction("DogsIndex"));
        }
Esempio n. 5
0
        public ActionResult Index(string sortOrder)
        {
            ViewBag.NameSortParm  = String.IsNullOrEmpty(sortOrder) ? "name_desc" : "";
            ViewBag.PriceSortParm = sortOrder == "Price" ? "Price_desc" : "Price";
            var service = new DogService();
            var dogs    = service.GetDogs();

            switch (sortOrder)
            {
            case "name_desc":
                dogs = dogs.OrderByDescending(s => s.DogName);
                break;

            case "Price":
                dogs = dogs.OrderBy(s => s.DogPrice);
                break;

            case "Price_desc":
                dogs = dogs.OrderByDescending(s => s.DogPrice);
                break;

            default:
                dogs = dogs.OrderBy(s => s.DogName);
                break;
            }
            return(View(dogs.ToList()));
        }
Esempio n. 6
0
        public ActionResult Details(int id)
        {
            var svc   = new DogService();
            var model = svc.GetDogById(id);

            return(View(model));
        }
Esempio n. 7
0
        public IList <Dog> Get()
        {
            IList <Dog> result = MemoryCache.Get <IList <Dog> >(cacheName);

            if (result == null)
            {
                Task <IList <Dog> > dbFetchTask = new Task <IList <Dog> >(() => DogService.Get());

                bool isRunning = false;
                lock (ThreadWatcher)
                {
                    isRunning = ThreadWatcher.IsRunning(cacheName);
                }
                if (!isRunning)
                {
                    ThreadStartedEvent?.Invoke(this, new ThreadStartedEvent(cacheName)); // Fire:a event.
                    dbFetchTask.Start();                                                 // Starta bara tråden, om det inte redan körs en sådan.
                }

                dbFetchTask.ContinueWith(x =>
                {
                    MemoryCache.Set(cacheName, x.Result, options: MemoryCacheEntryOptions);
                    ThreadFinishedEvent?.Invoke(this, new ThreadFinishedEvent(cacheName)); // Tala om att tråden är klar
                });
            }
            else
            {
                Console.WriteLine($"Used MemoryCache for {cacheName}.");
            }

            return(result);
        }
        private DogService CreateDogService()
        {
            var userId  = Guid.Parse(User.Identity.GetUserId());
            var service = new DogService(userId);

            return(service);
        }
Esempio n. 9
0
        public void TestGetDogFalseId(string id, int index)
        {
            var dogService = new DogService();

            dogService.PostDog(_dogList[index]);

            Assert.Throws <Exception>(() => dogService.GetDog(id));
        }
Esempio n. 10
0
        public ActionResult DeletePost(int id)
        {
            var service = new DogService();

            service.DeleteDog(id);
            TempData["SaveResult"] = "Dog deleted.";

            return(RedirectToAction("Index"));
        }
Esempio n. 11
0
        public void AdoptDog_When_Username_Killer()
        {
            var dogService = new DogService(new RefactorDogMockRepository(), new TicketService());
            var message    = dogService.AdoptDog(new DogBreedDto {
                Name = "Boxer"
            }, "Dog killer");

            Assert.AreEqual(message, MessagesDogs.DogCallPolice);
        }
Esempio n. 12
0
        public void TestGetImageBlankInput()
        {
            DogService dogService = new DogService();
            Image      response   = dogService.GetImage("");

            /* Null tests */
            Assert.IsNotNull(response);
            Assert.IsTrue(response.SourceString.Length == 0);
        }
Esempio n. 13
0
        public void TestGetDog(int index)
        {
            var dogService = new DogService();

            dogService.PostDog(_dogList[index]);
            var result = dogService.GetDog(_dogList[index].Id);

            Assert.AreEqual(_dogList[index], result);
        }
Esempio n. 14
0
        public void TestPostDogInvalidWeight(double weight)
        {
            var dogService = new DogService();
            var dog        = new Dog()
            {
                Id = "22222", Name = "Yuma", Weight = weight, Age = 3, Photo = _photoUrl
            };

            Assert.Throws <Exception>(() => dogService.PostDog(dog));
        }
Esempio n. 15
0
 public MainVM()
 {
     _svc        = new DogService();
     SomeCommand = new MyCommand()
     {
         CanExecuteFunc = obj => true,
         ExecuteFunc    = ChangeItems
     };
     Dogz = _svc.ShowRandomDogs();
 }
Esempio n. 16
0
        public void TestGetImageFail()
        {
            DogService dogService = new DogService();
            Image      response   = dogService.GetImage("somedogthatdoesntexist");

            /* Null tests */
            Assert.IsNotNull(response);

            Assert.IsTrue(response.SourceString.Length == 0);
        }
Esempio n. 17
0
        public void TestPostDogInvalidAge(int age)
        {
            var dogService = new DogService();
            var dog        = new Dog()
            {
                Id = "22222", Name = "Yuma", Weight = 12.3, Age = age, Photo = _photoUrl
            };

            Assert.Throws <Exception>(() => dogService.PostDog(dog));
        }
Esempio n. 18
0
        public void TestPostDogNullOrEmptyName(string name)
        {
            var dogService = new DogService();
            var dog        = new Dog()
            {
                Id = "22222", Name = name, Weight = 12.3, Age = 3, Photo = _photoUrl
            };

            Assert.Throws <Exception>(() => dogService.PostDog(dog));
        }
Esempio n. 19
0
        public void TestDeleteDogWithoutDogsPosted()
        {
            var dogService = new DogService();
            var dog        = new Dog()
            {
                Id = "222", Name = "Yuma", Weight = 12.3, Age = 3, Photo = _photoUrl
            };

            Assert.Throws <Exception>(() => dogService.DeleteDog(dog));
        }
Esempio n. 20
0
        public void TestGetImage()
        {
            DogService dogService = new DogService();
            Image      response   = dogService.GetImage("beagle");

            /* Null tests */
            Assert.IsNotNull(response);

            Assert.IsTrue(response.SourceString.Length > 0);
            Assert.IsTrue(response.SourceString.StartsWith("http"));
        }
Esempio n. 21
0
        public void TestGetBreedList()
        {
            DogService   dogService = new DogService();
            List <Breed> breedList  = dogService.GetBreedList();

            /* Null tests */
            Assert.IsNotNull(breedList);

            Assert.IsTrue(breedList.Count > 0);
            Assert.IsTrue(breedList.Exists(b => b.Variations.Count > 0));
        }
Esempio n. 22
0
        public void TestGetAllDogs()
        {
            var dogService = new DogService();

            dogService.PostDog(_dogList[0]);
            dogService.PostDog(_dogList[1]);
            dogService.PostDog(_dogList[2]);
            var result = dogService.GetDogs();

            Assert.AreEqual(_dogList, result);
        }
Esempio n. 23
0
        public void TestPostDog()
        {
            var dogService = new DogService();
            var dog        = new Dog()
            {
                Id = "22222", Name = "Yuma", Weight = 12.3, Age = 3, Photo = _photoUrl
            };
            var result = dogService.PostDog(dog);

            Assert.AreEqual(dog, result);
        }
Esempio n. 24
0
        public void TestPostDuplicateDog()
        {
            var dogService = new DogService();
            var dog        = new Dog()
            {
                Id = "22222", Name = "Yuma", Weight = 12.3, Age = 4, Photo = _photoUrl
            };

            dogService.PostDog(dog);

            Assert.Throws <Exception>(() => dogService.PostDog(dog));
        }
Esempio n. 25
0
        public DogListViewModel(IFlyoutManager flyoutManager)
        {
            _flyoutManager = flyoutManager;

            dogService = new DogService();

            dogList = dogService.GetDogs();

            dogListView = CollectionViewSource.GetDefaultView(dogList);

            editDogCommand = new DelegateCommand <Dog>(TriggerOpenFlyout);
        }
Esempio n. 26
0
        public void TestDeleteDogFalseDog(int index, string id)
        {
            var dogService = new DogService();

            dogService.PostDog(_dogList[index]);

            var dog = new Dog()
            {
                Id = id, Name = "Yuma", Weight = 12.3, Age = 3, Photo = _photoUrl
            };

            Assert.Throws <Exception>(() => dogService.DeleteDog(dog));
        }
Esempio n. 27
0
        // GET: RobsDogs
        public ActionResult Index()
        {
            var dogOwnerRepository = new DogOwnerRepository();
            var dogRepository      = new DogRepository();

            var dogOwnerService = new DogOwnerService(dogOwnerRepository);
            var dogService      = new DogService(dogRepository);

            var dogOwnerViewModelMapper = new DogOwnerViewModelMapper(dogOwnerService, dogService);
            var dogOwnerListViewModel   = dogOwnerViewModelMapper.GetAllDogOwners();

            return(View(dogOwnerListViewModel));
        }
Esempio n. 28
0
        public ActionResult Create()
        {
            ViewBag.Title = "New Event";
            List <Dog> Dogs  = new DogService().GetDogs().ToList();
            var        query = from d in Dogs
                               select new SelectListItem()
            {
                Value = d.DogId.ToString(),
                Text  = d.DogName
            };

            ViewBag.DogId = query.ToList();
            return(View());
        }
Esempio n. 29
0
        public void TestPutDog(int index)
        {
            var dogService = new DogService();

            dogService.PostDog(_dogList[index]);

            var dog = new Dog()
            {
                Id = _dogList[index].Id, Name = "Pixi", Weight = 11.4, Age = 5, Photo = _photoUrl
            };
            var result = dogService.PutDog(dog);

            Assert.AreEqual(dog, result);
        }
Esempio n. 30
0
        public async Task DogPic(CommandContext ctx)
        {
            var results = DogService.GetDogPhotoAsync().Result;

            if (results.Status != "success")
            {
                await BotServices.SendEmbedAsync(ctx, Resources.ERR_DOG_PHOTO, EmbedType.Warning).ConfigureAwait(false);
            }
            else
            {
                var output = new DiscordEmbedBuilder()
                             .WithImageUrl(results.Message)
                             .WithColor(DiscordColor.Brown);
                await ctx.RespondAsync(embed : output.Build()).ConfigureAwait(false);
            }
        }