コード例 #1
0
ファイル: RouteService.cs プロジェクト: AllahEdin/JwtNetCore
        protected override async Task <IRoute> Update(IContextProvider provider, IRoute model)
        {
            var routes =
                provider.GetTable <Route>()
                .Where(t => t.Id == model.Id);

            if (!routes.Any())
            {
                throw new InvalidOperationException($"No route with id = {model.Id}");
            }

            if (routes.Count() > 1)
            {
                throw new InvalidOperationException($"По идентификатор найдено более 1 соответствия");
            }

            var res =
                await provider.GetTable <Route>()
                .Where(t => t.Id == model.Id)
                .UpdateAsync(t => new Route()
            {
                CityId      = model.CityId > 0? model.CityId : t.CityId,
                DistrictId  = model.DistrictId > 0 ? model.DistrictId : t.DistrictId,
                Length      = model.Length > 0 ? model.Length : t.Length,
                Path        = string.IsNullOrEmpty(model.Path) ? t.Path : model.Path,
                Name        = string.IsNullOrEmpty(model.Name) ? t.Name : model.Name,
                Animals     = model.Animals,
                Time        = model.Time > 0 ? model.Time : t.Time,
                Weight      = model.Weight > 0 ? model.Weight : t.Weight,
                Visible     = model.Visible,
                Description = string.IsNullOrEmpty(model.Description) ? t.Description : model.Description
            });

            return(model);
        }
コード例 #2
0
        protected override async Task <IHotel> Update(IContextProvider provider, IHotel model)
        {
            var hotels =
                provider.GetTable <Hotel>()
                .Where(t => t.Id == model.Id);

            if (!hotels.Any())
            {
                throw new InvalidOperationException($"No hotel with id = {model.Id}");
            }

            if (hotels.Count() > 1)
            {
                throw new InvalidOperationException($"По идентификатор найдено более 1 соответствия");
            }

            var hotel =
                hotels.First();

            var res =
                await provider.GetTable <Hotel>()
                .Where(t => t.Id == model.Id)
                .UpdateAsync(t => new Hotel()
            {
                CityId        = model.CityId > 0 ? model.CityId : hotel.CityId,
                DistrictId    = model.DistrictId > 0 ? model.DistrictId : hotel.DistrictId,
                Discount      = model.Discount > -1 ? model.Discount: hotel.Discount,
                BuildDate     = model.BuildDate > default(DateTimeOffset) ? model.BuildDate : hotel.BuildDate,
                Address       = string.IsNullOrEmpty(model.Address) ? hotel.Address : model.Address,
                Name          = string.IsNullOrEmpty(model.Name) ? hotel.Name : model.Name,
                Description   = string.IsNullOrEmpty(model.Description) ? hotel.Description : model.Description,
                Latitude      = string.IsNullOrEmpty(model.Latitude) ? hotel.Latitude : model.Latitude,
                Longitude     = string.IsNullOrEmpty(model.Longitude) ? hotel.Longitude : model.Longitude,
                Path          = string.IsNullOrEmpty(model.Path) ? hotel.Path : model.Path,
                Preview       = string.IsNullOrEmpty(model.Preview) ? hotel.Preview : model.Preview,
                Phone         = string.IsNullOrEmpty(model.Phone) ? hotel.Phone : model.Phone,
                Url           = string.IsNullOrEmpty(model.Url) ? hotel.Url : model.Url,
                ClassType     = (model.ClassType > 0 && model.ClassType <= 5) ? model.ClassType : hotel.ClassType,
                HousingTypeId = model.HousingTypeId > 0 ? model.HousingTypeId : hotel.HousingTypeId,
                Weight        = model.Weight > 0 ? model.Weight : hotel.Weight,
            });

            return(model);
        }
コード例 #3
0
        protected override async Task <IRestaurant> Update(IContextProvider provider, IRestaurant model)
        {
            var rests =
                provider.GetTable <Restaurant>()
                .Where(t => t.Id == model.Id);

            if (!rests.Any())
            {
                throw new InvalidOperationException($"No restaurant with id = {model.Id}");
            }

            if (rests.Count() > 1)
            {
                throw new InvalidOperationException($"По идентификатор найдено более 1 соответствия");
            }

            var rest =
                rests.First();

            var res =
                await provider.GetTable <Restaurant>()
                .Where(t => t.Id == model.Id)
                .UpdateAsync(t => new Restaurant()
            {
                CityId         = model.CityId > 0 ? model.CityId : rest.CityId,
                DistrictId     = model.DistrictId > 0 ? model.DistrictId : rest.DistrictId,
                BuildDate      = model.BuildDate > default(DateTimeOffset) ? model.BuildDate : rest.BuildDate,
                Address        = string.IsNullOrEmpty(model.Address) ? rest.Address : model.Address,
                CateringTypeId = model.CateringTypeId > 0 ? model.CateringTypeId : rest.CateringTypeId,
                Name           = string.IsNullOrEmpty(model.Name) ? rest.Name : model.Name,
                Description    = string.IsNullOrEmpty(model.Description) ? rest.Description : model.Description,
                Latitude       = string.IsNullOrEmpty(model.Latitude) ? rest.Latitude : model.Latitude,
                Longitude      = string.IsNullOrEmpty(model.Longitude) ? rest.Longitude : model.Longitude,
                Path           = string.IsNullOrEmpty(model.Path) ? rest.Path : model.Path,
                Preview        = string.IsNullOrEmpty(model.Preview) ? rest.Preview : model.Preview,
                Url            = string.IsNullOrEmpty(model.Url) ? rest.Url : model.Url,
                Phone          = string.IsNullOrEmpty(model.Phone) ? rest.Phone : model.Phone,
                Discount       = model.Discount > -1 ? model.Discount : rest.Discount,
                Weight         = model.Weight > 0 ? model.Weight : rest.Weight,
            });

            return(model);
        }
コード例 #4
0
ファイル: EventService.cs プロジェクト: AllahEdin/JwtNetCore
        protected override async Task <IEvent> Update(IContextProvider provider, IEvent model)
        {
            var events =
                provider.GetTable <Event>()
                .Where(t => t.Id == model.Id);

            if (!events.Any())
            {
                throw new InvalidOperationException($"No event with id = {model.Id}");
            }

            if (events.Count() > 1)
            {
                throw new InvalidOperationException($"По идентификатор найдено более 1 соответствия");
            }

            var eventdb =
                events.First();

            var res =
                await provider.GetTable <Event>()
                .Where(t => t.Id == model.Id)
                .UpdateAsync(t => new Event()
            {
                CityId      = model.CityId > 0 ? model.CityId : eventdb.CityId,
                DistrictId  = model.DistrictId > 0 ? model.DistrictId : eventdb.DistrictId,
                Discount    = model.Discount > -1 ? model.Discount : eventdb.Discount,
                Address     = string.IsNullOrEmpty(model.Address) ? eventdb.Address : model.Address,
                Name        = string.IsNullOrEmpty(model.Name) ? eventdb.Name : model.Name,
                Description = string.IsNullOrEmpty(model.Description) ? eventdb.Description : model.Description,
                Latitude    = string.IsNullOrEmpty(model.Latitude) ? eventdb.Latitude : model.Latitude,
                Longitude   = string.IsNullOrEmpty(model.Longitude) ? eventdb.Longitude : model.Longitude,
                Path        = string.IsNullOrEmpty(model.Path) ? eventdb.Path : model.Path,
                Preview     = string.IsNullOrEmpty(model.Preview) ? eventdb.Preview : model.Preview,
                Phone       = string.IsNullOrEmpty(model.Phone) ? eventdb.Phone : model.Phone,
                Url         = string.IsNullOrEmpty(model.Url) ? eventdb.Url : model.Url,
                Weight      = model.Weight > 0 ? model.Weight : eventdb.Weight,
                StartDate   = model.StartDate,
                EndDate     = model.EndDate
            });

            return(model);
        }
コード例 #5
0
        protected override async Task <IAttraction> Update(IContextProvider provider, IAttraction model)
        {
            var attractions =
                provider.GetTable <Attraction>()
                .Where(t => t.Id == model.Id);

            if (!attractions.Any())
            {
                throw new InvalidOperationException($"No attraction with id = {model.Id}");
            }

            if (attractions.Count() > 1)
            {
                throw new InvalidOperationException($"По идентификатор найдено более 1 соответствия");
            }

            var attraction =
                attractions.First();

            var res =
                await provider.GetTable <Attraction>()
                .Where(t => t.Id == model.Id)
                .UpdateAsync(t => new Attraction()
            {
                CityId      = model.CityId > 0 ? model.CityId : attraction.CityId,
                DistrictId  = model.DistrictId > 0 ? model.DistrictId : attraction.DistrictId,
                Discount    = model.Discount > -1 ? model.Discount : attraction.Discount,
                BuildDate   = model.BuildDate > default(DateTimeOffset) ? model.BuildDate : attraction.BuildDate,
                Address     = string.IsNullOrEmpty(model.Address) ? attraction.Address : model.Address,
                Name        = string.IsNullOrEmpty(model.Name) ? attraction.Name : model.Name,
                Description = string.IsNullOrEmpty(model.Description) ? attraction.Description : model.Description,
                Latitude    = string.IsNullOrEmpty(model.Latitude) ? attraction.Latitude : model.Latitude,
                Longitude   = string.IsNullOrEmpty(model.Longitude) ? attraction.Longitude : model.Longitude,
                Path        = string.IsNullOrEmpty(model.Path) ? attraction.Path : model.Path,
                Preview     = string.IsNullOrEmpty(model.Preview) ? attraction.Preview : model.Preview,
                Duration    = model.Duration > 0 ? model.Duration : attraction.Duration,
                Weight      = model.Weight > 0 ? model.Weight : attraction.Weight,
            });

            return(model);
        }
コード例 #6
0
        protected override async Task <T> Update(IContextProvider provider, T model)
        {
            var res =
                await provider.GetTable <TDb>()
                .Where(t => t.Id == model.Id)
                .UpdateAsync(e => new TDb()
            {
                Name = model.Name
            });

            return(model);
        }
コード例 #7
0
        protected override async Task <IDictionary> Update(IContextProvider provider, IDictionary model)
        {
            var res =
                await provider.GetTable <Dictionary>()
                .Where(t => t.Id == model.Id)
                .UpdateAsync(e => new Dictionary()
            {
                Code = model.Code
            });

            return(model);
        }
コード例 #8
0
        protected override async Task <IDictionaryRow> Update(IContextProvider provider, IDictionaryRow model)
        {
            var res =
                await provider.GetTable <DictionaryRow>()
                .Where(t => t.Id == model.Id)
                .UpdateAsync(e => new DictionaryRow()
            {
                Value  = string.IsNullOrEmpty(model.Value) ? e.Value : model.Value,
                Weight = model.Weight == 0 ? e.Weight : model.Weight,
            });

            return(model);
        }
コード例 #9
0
ファイル: UserService.cs プロジェクト: AllahEdin/JwtNetCore
        private async Task <AspNetRole> SetDefaultRole(IContextProvider cp, string usrId)
        {
            var role = cp
                       .GetTable <AspNetRole>()
                       .FirstOrDefault(t => t.RoleName == "user");

            if (role == null)
            {
                throw new InvalidOperationException();
            }

            var userRole =
                new AspNetUserRole()
            {
                AspNetUserId = usrId,
                RoleId       = role.Id,
            };

            await cp.InsertNonEntityAsync(userRole);

            return(role);
        }