public async Task <int> EditUserBeehiveAsync( int beehiveId, int number, BeehiveSystem beehiveSystem, BeehiveType beehiveType, DateTime dateTime, int apiaryId, BeehivePower beehivePower, bool hasDevice, bool hasPolenCatcher, bool hasPropolisCatcher, bool isItMovable) { var beehive = this.beehiveRepository .All() .FirstOrDefault(b => b.Id == beehiveId); beehive.Number = number; beehive.BeehiveSystem = beehiveSystem; beehive.BeehiveType = beehiveType; beehive.BeehivePower = beehivePower; beehive.Date = dateTime; beehive.ApiaryId = apiaryId; beehive.HasDevice = hasDevice; beehive.HasPolenCatcher = hasPolenCatcher; beehive.HasPropolisCatcher = hasPropolisCatcher; beehive.IsItMovable = isItMovable; await this.beehiveRepository.SaveChangesAsync(); return(beehive.Id); }
public async Task <int> CreateBeehiveAsync( string ownerId, string creatorId, int number, BeehiveSystem beehiveSystem, BeehiveType beehiveType, DateTime dateTime, int apiaryId, BeehivePower beehivePower, bool hasDevice, bool hasPolenCatcher, bool hasPropolisCatcher, bool isItMovable) { var beehive = new Beehive { CreatorId = creatorId, OwnerId = ownerId, Number = number, BeehiveSystem = beehiveSystem, BeehiveType = beehiveType, BeehivePower = beehivePower, Date = dateTime, ApiaryId = apiaryId, HasDevice = hasDevice, HasPolenCatcher = hasPolenCatcher, HasPropolisCatcher = hasPropolisCatcher, IsItMovable = isItMovable, }; await this.beehiveRepository.AddAsync(beehive); await this.beehiveRepository.SaveChangesAsync(); if (beehive.Apiary.ApiaryType == ApiaryType.Movable) { await this.temporaryApiaryBeehiveService.AddBeehiveToApiary(apiaryId, beehive.Id); } var allApiaryHelpersIds = this.apiaryHelperRepository .All() .Where(x => x.ApiaryId == apiaryId) .Select(x => x.UserId); foreach (var helperId in allApiaryHelpersIds) { var helper = new BeehiveHelper { UserId = helperId, BeehiveId = beehive.Id, }; await this.beehiveHelperRepository.AddAsync(helper); } await this.beehiveHelperRepository.SaveChangesAsync(); return(beehive.Id); }