public async Task <ActionResult> DeleteConfirmed(int id)
        {
            OwnerProfile Profile = await db.Profiles.FindAsync(id);

            db.Profiles.Remove(Profile);
            await db.SaveChangesAsync();

            return(RedirectToAction("MyPetProfile"));
        }
        public async Task SaveAsyncWhenSaveReturnsSaved()
        {
            //Arrange
            var mockOwnerProfileRepository  = GetDefaultIOwnerProfileRepositoryInstance();
            var mockOwnerLocationRepository = GetDefaultIOwnerLocationRepositoryInstance();
            var mockPetOwnerRepository      = GetDefaultIPetOwnerRepositoryInstance();
            var mockUnitOfWork         = GetDefaultIUnitOfWorkInstance();
            var mockProvinceRepository = GetDefaultIProvinceRepositoryInstance();
            var mockCityRepository     = GetDefaultICityRepositoryInstance();
            var mockUserRepository     = GetDefaultIUserRepositoryInstance();

            User user = new User {
                Id = 1, Mail = "*****@*****.**", UserTypeVet = false
            };
            Province province = new Province {
                Id = 1, Name = "Lima"
            };
            City city = new City {
                Id = 10, Name = "SJL", ProvinceId = 1
            };
            OwnerProfile ownerProfile = new OwnerProfile {
                Id = 10, Name = "Julio"
            };

            mockUserRepository.Setup(p => p.AddAsync(user))
            .Returns(Task.FromResult <User>(user));

            mockUserRepository.Setup(p => p.FindByIdAsync(1))
            .Returns(Task.FromResult <User>(user));

            mockProvinceRepository.Setup(p => p.AddAsync(province))
            .Returns(Task.FromResult <Province>(province));

            mockProvinceRepository.Setup(p => p.FindById(1))
            .Returns(Task.FromResult <Province>(province));

            mockCityRepository.Setup(r => r.AddAsync(city))
            .Returns(Task.FromResult <City>(city));

            mockCityRepository.Setup(p => p.FindById(10))
            .Returns(Task.FromResult <City>(city));

            mockOwnerProfileRepository.Setup(r => r.AddAsync(ownerProfile))
            .Returns(Task.FromResult <OwnerProfile>(ownerProfile));

            var service = new OwnerProfileService(mockUnitOfWork.Object, mockPetOwnerRepository.Object, mockOwnerLocationRepository.Object,
                                                  mockOwnerProfileRepository.Object, mockProvinceRepository.Object, mockCityRepository.Object, mockUserRepository.Object);

            //Act
            OwnerProfileResponse result = await service.SaveAsync(1, 10, 1, ownerProfile);

            //Arrange
            result.Resource.Should().Be(ownerProfile);
        }
        public async Task <ActionResult> Edit([Bind(Include = "OwnerID,UserName,PassHash,FName,LName,Pets,Zipcode,PhoneNum,Email")] OwnerProfile Profile)
        {
            if (ModelState.IsValid)
            {
                db.Entry(Profile).State = System.Data.Entity.EntityState.Modified;
                await db.SaveChangesAsync();

                return(RedirectToAction("MyPetProfile"));
            }
            return(View(Profile));
        }
        public async Task <ActionResult> Create([Bind(Include = "OwnerID,UserName,PassHash,FName,LName,Pets,Zipcode,PhoneNum,Email")] OwnerProfile Profile)
        {
            if (ModelState.IsValid)
            {
                db.Profiles.Add(Profile);
                await db.SaveChangesAsync();

                return(RedirectToAction("MyPetProfile"));
            }

            return(View(Profile));
        }
        // GET: Products/Edit/5
        public async Task <ActionResult> Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            OwnerProfile Profile = await db.Profiles.FindAsync(id);

            if (Profile == null)
            {
                return(HttpNotFound());
            }
            return(View(Profile));
        }
        public async Task <OwnerProfileResponse> UpdateAsync(int id, OwnerProfile ownerProfile)
        {
            var existingOwnerProfile = await _ownerProfileRepository.FindById(id);

            if (existingOwnerProfile == null)
            {
                return(new OwnerProfileResponse("Owner Profile not found"));
            }
            existingOwnerProfile.Name             = ownerProfile.Name;
            existingOwnerProfile.TelephonicNumber = ownerProfile.TelephonicNumber;
            try
            {
                _ownerProfileRepository.Update(ownerProfile);
                await _unitOfWork.CompleteAsync();

                return(new OwnerProfileResponse(existingOwnerProfile));
            }
            catch (Exception ex)
            {
                return(new OwnerProfileResponse($"An error ocurred while updating owner profile: {ex.Message}"));
            }
        }
Esempio n. 7
0
        static void Main(string[] args)
        {
            try
            {    /*  #Instances
                  * Create an instance to the class.
                  *   Create the instances that are in the constructor
                  */
                _ownerProfile               = new OwnerProfile();
                _gameInformation            = new GameInformation();
                _gameInformationClassicMode = new GameInformationClassicMode();
                _SecondChanceQuestion       = new GameInformationClassicMode.SecondChanceQuestion();
                _variables          = new Variables();
                _handlerFiddlerCore = new HandlerFiddlerCore();
                _consoleOutput      = new ConsoleOutput();
                /* #EndInstances*/

                handler = new ConsoleEventDelegate(ConsoleEventCallback); //Instance for the method ConsoleEventCallback
                SetConsoleCtrlHandler(handler, true);                     // Call to the API SetConsoleCtrlHandler
                _consoleOutput.ConsoleWelcome();
                _handlerFiddlerCore.Start();                              // Start the proxy, install the certificate and the event for sessions capture
                _consoleOutput.WriteLine("Inicie ahora sesión en FaceBook si aún no lo hizo y luego entre en alguna partida que sea modo Clásico. \nEsperando...", "Cheat");
                _variables.ImStarted = true;
                _consoleOutput.WriteLine("");
                while (true)
                {
                    System.Threading.Thread.Sleep(1800000);
                }                                                        // Prevent the application from closing
            }
            catch (Exception e)
            {
                _consoleOutput.WriteError(e);
                _handlerFiddlerCore.Stop();
                Certificate.Uninstall();
                _consoleOutput.WriteLine("\n\nThe application will close after pressing a key");
                Console.ReadKey();
            }
        }
        public async Task <OwnerProfileResponse> SaveAsync(int provinceId, int cityId, int userId, OwnerProfile ownerProfile)
        {
            var existingProvince = await _provinceRepository.FindById(provinceId);

            var existingCity = await _cityRepository.FindById(cityId);

            var existingUser = await _userRepository.FindByIdAsync(userId);

            if (existingProvince == null)
            {
                return(new OwnerProfileResponse("Province not found, a owner needs a province to exist"));
            }
            if (existingCity == null)
            {
                return(new OwnerProfileResponse("City not found, a owner needs a city to exist"));
            }
            if (existingCity.ProvinceId != provinceId)
            {
                return(new OwnerProfileResponse("The City does not exist in the province"));
            }
            if (existingUser == null)
            {
                return(new OwnerProfileResponse("The User does not exist, a profile of owner depends of an user"));
            }
            IEnumerable <OwnerProfile> ownerProfiles = await ListAsync();

            List <OwnerProfile> ownerProfilesList = ownerProfiles.ToList();
            bool differentUserId = true;

            if (ownerProfilesList != null)
            {
                ownerProfilesList.ForEach(ownerP =>
                {
                    if (ownerP.UserId == userId)
                    {
                        differentUserId = false;
                    }
                });
            }

            if (!differentUserId)
            {
                return(new OwnerProfileResponse("The User is on used of other profile"));
            }

            if (existingUser.UserTypeVet == true)
            {
                return(new OwnerProfileResponse("The User is for vet profiles"));
            }

            try
            {
                await _ownerProfileRepository.AddAsync(ownerProfile);

                await _unitOfWork.CompleteAsync();

                return(new OwnerProfileResponse(ownerProfile));
            }
            catch (Exception ex)
            {
                return(new OwnerProfileResponse($"An error ocurred while saving owner profile: {ex.Message}"));
            }
        }
 public void Update(OwnerProfile ownerProfile)
 {
     _context.OwnerProfiles.Update(ownerProfile);
 }
 public void Remove(OwnerProfile ownerProfile)
 {
     _context.OwnerProfiles.Remove(ownerProfile);
 }
 public async Task AddAsync(OwnerProfile ownerProfile)
 {
     await _context.OwnerProfiles.AddAsync(ownerProfile);
 }