Esempio n. 1
0
        public bool ChangeEvent(ChangeModel changedModel)
        {
            using (var ctx = new EventContext())
            {
               var changeEvent =  ctx.Events.Include("City").Include("Publisher").FirstOrDefault(e => e.Id == changedModel.Id);
               if (changeEvent != default(EventModel))
               {
                   changeEvent.Description = changedModel.Description;
                   changeEvent.EndTime = changedModel.EndTime;
                   changeEvent.Enter = changedModel.Enter;
                   changeEvent.IsCharitable = changedModel.IsCharitable;
                   changeEvent.isFreeEntrance = changedModel.IsFreeEntrance;
                   changeEvent.Organizers = changedModel.Organizers;
                   changeEvent.PersonsCategory = ctx.PersonCategories.FirstOrDefault(p=>p.Id == changedModel.SelectedPersonsCategoryId);
                   //changeEvent.Photos = changedModel.Photos;
                   changeEvent.Place = changedModel.Place;
                   changeEvent.ShortDescription = changedModel.ShortDescription;
                   changeEvent.Sponsors = changedModel.Sponsors;
                   changeEvent.StartTime = changedModel.StartTime;
                   changeEvent.Title = changedModel.Title;
                   changeEvent.Type = ctx.EventTypes.FirstOrDefault(t=>t.Id == changedModel.SelectedTypeId);

                   ctx.SaveChanges();
               }
            }
            return true;
        }
Esempio n. 2
0
        public bool AddLike(int id, bool likes, string login)
        {
            using (var ctx = new EventContext())
            {
                var customer = ctx.Customers.FirstOrDefault(e => e.Login == login);
                var curEvent = ctx.Events.FirstOrDefault(e => e.Id == id);
                if (curEvent != default(EventModel) &&
                    customer != default(EventCustomer) && !customer.IsBan && !customer.IsDeleted)
                {
                    if (likes)
                    {
                        if (!LikeTransfer(curEvent.Likes, curEvent.Dislikes, login, ctx))
                        {
                            return false;
                        }
                    }
                    else
                    {
                        if (!LikeTransfer(curEvent.Dislikes, curEvent.Likes, login, ctx))
                        {
                            return false;
                        }
                    }

                    if (AddNewLike(likes, ctx, curEvent, customer))
                    {
                        ctx.SaveChanges();
                        return true;
                    }
                }
                return false;
            }
        }
Esempio n. 3
0
 public List<EventType> GetAllEventTypes()
 {
     using (var ctx = new EventContext())
     {
         return ctx.EventTypes.OrderBy(r => r.Id).ToList();
     }
 }
Esempio n. 4
0
        public bool Delete(object name)
        {
            int eventTypeId = Convert.ToInt32(name);
            using (var ctx = new EventContext())
            {
                var delType = (from p in ctx.EventTypes
                               where p.Id == eventTypeId
                               select p).FirstOrDefault();

                if (delType != default(EventType))
                {
                    try
                    {
                        ctx.EventTypes.Remove(delType);
                        ctx.SaveChanges();
                        return true;
                    }
                    catch (Exception e)
                    {
                        return false;
                    }
                }
                return false;
            }
        }
Esempio n. 5
0
 public List<EventCountry> GetAllCountries()
 {
     using (var ctx = new EventContext())
     {
         return ctx.Countries.Include("Regions").ToList();
     }
 }
Esempio n. 6
0
        //int id, string pass, string name, string lastName, DateTime birth, string mobile,
        //string email, string country, string address, bool showContacts)
        public bool ChangeUserInfo(EventCustomer model)
        {
            using (var ctx = new EventContext())
            {
                var current = ctx.Customers.FirstOrDefault(c => c.Id == model.Id);
                if (current != default(EventCustomer))
                {
                    if (!string.IsNullOrEmpty(model.Password))
                    {
                        string newPass = Encrypt.GetEncryptedPassword(model.Password, current.Salt);
                        current.Password = newPass;
                    }
                    current.Name = model.Name;
                    current.LastName = model.LastName;
                    current.Birthday = model.Birthday;
                    current.Mobile = model.Mobile;
                    current.Email = model.Email;
                    current.Country = model.Country;
                    current.Address = model.Address;
                    current.ShowContacts = model.ShowContacts;
                    current.Rating = current.Rating;
                    current.Permissions = current.Permissions;

                    ctx.SaveChanges();
                    return true;
                }
            }
            return false;
        }
Esempio n. 7
0
 public List<EventPermission> GetAllPermissions()
 {
     using (var ctx = new EventContext())
     {
         return ctx.Permissions.OrderBy(r => r.Id).ToList();
     }
 }
Esempio n. 8
0
 public List<EventModel> GetAllEvents()
 {
     using (var ctx = new EventContext())
     {
         return ctx.Events.Include("Type").Include("PersonsCategory")
             .Include("Publisher").Include("City").Include("City.Region")
             .Include("City.Region.Country").Include("Likes").Include("Dislikes").ToList();
     }
 }
Esempio n. 9
0
 public bool Add(string name, int id = -1)
 {
     using (var ctx = new EventContext())
     {
         ctx.Countries.Add(new EventCountry { Country = name });
         ctx.SaveChanges();
         return true;
     }
 }
 public EventPermission GetPermission(string type)
 {
     using(var ctx = new EventContext())
     {
         var rating = ctx.Permissions.FirstOrDefault(p=>p.Type == type);
         if(rating != default(EventPermission))
         {
             return rating;
         }
         return null;
     }
 }
Esempio n. 11
0
 public bool isExist(string name, int id = -1)
 {
     using (var ctx = new EventContext())
     {
         var country = (from c in ctx.Countries
                        where c.Country == name
                        select c).FirstOrDefault();
         if (country != default(EventCountry))
         {
             return true;
         }
     }
     return false;
 }
Esempio n. 12
0
        public bool isExist(string name, int id = -1)
        {
            using (var ctx = new EventContext())
            {
                var suchType = (from t in ctx.EventTypes
                                where t.Type == name
                                select t).FirstOrDefault();

                if (suchType != default(EventType))
                {
                    return true;
                }
                return false;
            }
        }
Esempio n. 13
0
        public bool isExist(string name, int id = -1)
        {
            using (var ctx = new EventContext())
            {
                var suchCategory = (from t in ctx.PersonCategories
                                    where t.Category == name
                                    select t).FirstOrDefault();

                if (suchCategory != default(EventPersonCategory))
                {
                    return true;
                }
                return false;
            }
        }
Esempio n. 14
0
        public bool isExist(string name, int id = -1)
        {
            using (var ctx = new EventContext())
            {
                var city = (from c in ctx.Cities
                            where c.CityName == name && c.Region.Id == id
                            select c).FirstOrDefault();

                if (city != default(EventCity))
                {
                    return true;
                }
            }
            return false;
        }
Esempio n. 15
0
        public bool isExist(string name, int id = -1)
        {
            using (var ctx = new EventContext())
            {
                var suchRating = (from t in ctx.Ratings
                                  where t.Name == name
                                  select t).FirstOrDefault();

                if (suchRating != default(EventRating))
                {
                    return true;
                }
                return false;
            }
        }
Esempio n. 16
0
        public bool isExist(string name, int id = -1)
        {
            using (var ctx = new EventContext())
            {
                var suchRegion = (from r in ctx.Regions
                                  where r.RegionName == name && r.Country.Id == id
                                  select r).FirstOrDefault();

                if (suchRegion != default(EventRegion))
                {
                    return true;
                }
            }
            return false;
        }
Esempio n. 17
0
        public bool ChangeMainPhoto(int id, string newImage)
        {
            using (var ctx = new EventContext())
            {
                var edit = ctx.Events.Include("City").Include("Publisher").Include("Type").Include("PersonsCategory")
                    .FirstOrDefault(e => e.Id == id);

                if (edit != default(EventModel))
                {
                    edit.MainPhoto = newImage;
                    ctx.SaveChanges();
                    return true;
                }
            }
            return false;
        }
 public bool Edit(int actualId, string newName)
 {
     using (var ctx = new EventContext())
     {
         try
         {
             ctx.Permissions.Where(p => p.Id == actualId).FirstOrDefault().Type = newName;
             ctx.SaveChanges();
             return true;
         }
         catch (Exception e)
         {
             return false;
         }
     }
 }
Esempio n. 19
0
        public bool Add(string name, int id = -1)
        {
            using (var ctx = new EventContext())
            {
                var thisRegion = (from c in ctx.Regions
                                  where c.Id == id
                                  select c).FirstOrDefault();

                if (thisRegion != default(EventRegion))
                {
                    ctx.Cities.Add(new EventCity { CityName = name, Region = thisRegion });
                    ctx.SaveChanges();
                    return true;
                }
                return false;
            }
        }
Esempio n. 20
0
        public bool Add(string name, int id = -1)
        {
            using (var ctx = new EventContext())
            {
                foreach (var r in ctx.Ratings)
                {
                    if (r.Name == name)
                    {
                        return false;
                    }
                }

                ctx.Ratings.Add(new EventRating { Name = name });
                ctx.SaveChanges();
                return true;
            }
        }
        public bool Add(string name, int id = -1)
        {
            using (var ctx = new EventContext())
            {
                foreach (var p in ctx.Permissions)
                {
                    if (p.Type == name)
                    {
                        return false;
                    }
                }

                ctx.Permissions.Add(new EventPermission { Type = name });
                ctx.SaveChanges();
                return true;
            }
        }
Esempio n. 22
0
        public bool Add(string name, int id = -1)
        {
            using (var ctx = new EventContext())
            {
                foreach (var p in ctx.PersonCategories)
                {
                    if (p.Category == name)
                    {
                        return false;
                    }
                }

                ctx.PersonCategories.Add(new EventPersonCategory { Category = name });
                ctx.SaveChanges();
                return true;
            }
        }
Esempio n. 23
0
        public bool Add(string name, int id = -1)
        {
            using (var ctx = new EventContext())
            {
                var thisCountry = (from c in ctx.Countries
                                   where c.Id == id
                                   select c).FirstOrDefault();

                if (thisCountry != default(EventCountry))
                {
                    ctx.Regions.Add(new EventRegion { RegionName = name, Country = thisCountry });
                    ctx.SaveChanges();
                    return true;
                }
                return false;
            }
        }
Esempio n. 24
0
        public bool Edit(int actualId, string newName)
        {
            using (var ctx = new EventContext())
            {
                var editC = (from c in ctx.Countries
                             where c.Id == actualId
                             select c).FirstOrDefault();

                if (editC != default(EventCountry))
                {
                    editC.Country = newName;
                    ctx.SaveChanges();
                    return true;
                }
            }

            return false;
        }
Esempio n. 25
0
        public bool Delete(object name)
        {
            int countryId = Convert.ToInt32(name);
            using (var ctx = new EventContext())
            {
                var delCountry = (from c in ctx.Countries
                                  where c.Id == countryId
                                  select c).FirstOrDefault();

                if (delCountry != default(EventCountry))
                {
                    ctx.Countries.Remove(delCountry);
                    ctx.SaveChanges();
                    return true;
                }
            }
            return false;
        }
Esempio n. 26
0
        public bool Delete(object name)
        {
            int regionId = Convert.ToInt32(name);
            using (var ctx = new EventContext())
            {
                var delregion = (from c in ctx.Regions
                                 where c.Id == regionId
                                 select c).FirstOrDefault();

                if (delregion != default(EventRegion))
                {
                    ctx.Regions.Remove(delregion);
                    ctx.SaveChanges();
                    return true;
                }
            }
            return false;
        }
Esempio n. 27
0
        public bool Edit(int actualId, string newName)
        {
            using (var ctx = new EventContext())
            {
                var editR = (from r in ctx.Regions
                             where r.Id == actualId
                             select r).FirstOrDefault();

                if (editR != default(EventRegion))
                {
                    editR.RegionName = newName;
                    editR.Country = editR.Country;
                    ctx.SaveChanges();
                    return true;
                }
            }
            return false;
        }
Esempio n. 28
0
        public bool ChangePhoto(int userId, string content)
        {
            using (var ctx = new EventContext())
            {
                var editC = (from c in ctx.Customers
                             where c.Id == userId
                             select c).FirstOrDefault();

                if (editC != default(EventCustomer))
                {
                    editC.Photo = content;
                    editC.Rating = editC.Rating;
                    editC.Permissions = editC.Permissions;
                    ctx.SaveChanges();
                    return true;
                }
            }
            return false;
        }
Esempio n. 29
0
        public bool Edit(int actualId, string newName)
        {
            using (var ctx = new EventContext())
            {
                var editC = (from r in ctx.Cities
                             where r.Id == actualId
                             select r).FirstOrDefault();

                if (editC != default(EventCity))
                {
                    editC.CityName = newName;
                    editC.Region = editC.Region;
                    ctx.SaveChanges();
                    return true;
                }

            }
            return false;
        }
Esempio n. 30
0
        public bool AddToBanList(int userId)
        {
            using (var ctx = new EventContext())
            {
                var editC = (from c in ctx.Customers
                             where c.Id == userId
                             select c).FirstOrDefault();

                if (editC != default(EventCustomer))
                {
                    editC.IsBan = true;
                    editC.Rating = editC.Rating;
                    editC.Permissions = editC.Permissions;
                    ctx.SaveChanges();
                    return true;
                }

            }
            return false;
        }