Beispiel #1
0
        public ExcursionSightsControllerTests() : base()
        {
            apiRoute = "excursionsights";
            var stringContent = new StringContent(JsonConvert.SerializeObject(new RegisterDto {
                Email = "*****@*****.**", FirstName = "Aaaa", LastName = "Aaa", Password = "******"
            }), Encoding.UTF8, "application/json");
            var response       = client.PostAsync("accounts/register", stringContent);
            var jsonString     = response.Result.Content.ReadAsStringAsync();
            var model          = JsonConvert.DeserializeObject <bool>(jsonString.Result);
            var stringContent2 = new StringContent(JsonConvert.SerializeObject(new LoginDto {
                Email = "*****@*****.**", Password = "******"
            }), Encoding.UTF8, "application/json");
            var response2   = client.PostAsync("accounts/login", stringContent2);
            var jsonString2 = response2.Result.Content.ReadAsStringAsync();
            var model2      = JsonConvert.DeserializeObject <User>(jsonString2.Result);

            client.DefaultRequestHeaders.Add("Authorization", $"Bearer {model2.Token}");
            unexistingExcursionId = Guid.Parse("ffa5e70a-8338-4135-85d5-0fbe348cc697");
            unexistingSightId     = Guid.Parse("ffa5e70a-8338-4135-85d5-0fbe348cc693");
            testExcursionSight1   = new ExcursionSight {
                SightId = Guid.Parse("0f7ef80b-36f6-42b1-996e-421664c7ada7"), ExcursionId = Guid.Parse("57a55c05-b671-4edd-b63f-92c9561e4364")
            };
            testExcursionSight2 = new ExcursionSight {
                SightId = Guid.Parse("0f7ef80b-36f6-42b1-996e-421664c7ada5"), ExcursionId = Guid.Parse("57a55c05-b671-4edd-b63f-92c9561e4365")
            };
        }
        public async Task <Tuple <Guid, Guid> > Delete(Guid excursionId, Guid sightId)
        {
            ExcursionSight exs = new ExcursionSight {
                ExcursionId = excursionId, SightId = sightId
            };

            _dbContext.ExcursionSights.Attach(exs);
            _dbContext.ExcursionSights.Remove(exs);
            await _dbContext.SaveChangesAsync();

            return(new Tuple <Guid, Guid>(excursionId, sightId));
        }
        public Guid Create(string name, Guid idExcursion)
        {
            var newSight = new ExcursionSight()
            {
                Id          = Guid.NewGuid(),
                Name        = name,
                ExcursionId = idExcursion
            };

            _excursionSights.Create(newSight);

            return(newSight.Id);
        }
        public async Task <ExcursionSight> Create(Guid excursionId, Guid sightId)
        {
            ExcursionSight exs = new ExcursionSight {
                ExcursionId = excursionId, SightId = sightId
            };

            if (!Contains(exs))
            {
                await _dbContext.ExcursionSights.AddAsync(exs);

                await _dbContext.SaveChangesAsync();

                return(exs);
            }
            return(null);
        }
 public static int AddExcursionSight(ExcursionSight objSight)
 {
     try
     {
         using (UserContext db = new UserContext())
         {
             db.ExcursionSights.Add(objSight);
             db.SaveChanges();
             return(objSight.ExcursionSightId);
         }
     }
     catch
     {
         return(-1);
     }
 }
        public static int GetExcursionSightId(string ExcursionSightName, int ExcursionId)
        {
            int            ExcursionSightId = -1;
            ExcursionSight ExcursionSightExist;

            ExcursionSightExist = ExcursionManager.GetExcursionSightExist(ExcursionSightName, ExcursionId);
            if (ExcursionSightExist == null)
            {
                ExcursionSight objSight = new ExcursionSight
                {
                    ExcursionSightName = ExcursionSightName,
                    ExcursionId        = ExcursionId
                };
                ExcursionSightId = ExcursionManager.AddExcursionSight(objSight);
            }
            return(ExcursionSightExist != null ? ExcursionSightExist.ExcursionSightId : ExcursionSightId);
        }
 private bool Contains(ExcursionSight exs)
 {
     return(_dbContext.ExcursionSights.FirstOrDefault(x => x.ExcursionId == exs.ExcursionId && x.SightId == exs.SightId) != null);
 }