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 void CreateMultiple( int apiaryId, int firstNumber, int lastNumber, SystemType systemType, BeehiveType beehiveType) { var beehives = new List <Beehive>(); for (int number = firstNumber; number <= lastNumber; number++) { var beehive = new Beehive { ApiaryId = apiaryId, Number = number, SystemType = systemType, BeehiveType = beehiveType, IsAlive = true, }; beehives.Add(beehive); } this.db.Beehives.AddRange(beehives); this.db.SaveChanges(); AddMultipleBeehivesToApiary(apiaryId, beehives); }
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); }
public async Task EditAsync( int beehiveId, int number, SystemType systemType, BeehiveType beehiveType) { var beehive = this.FindById(beehiveId); if (beehive == null) { return; } beehive.Number = number; beehive.SystemType = systemType; beehive.BeehiveType = beehiveType; beehive.ModifiedOn = DateTime.UtcNow; await this.db.SaveChangesAsync(); }
public async Task <int> CreateAsync( int apiaryId, int number, SystemType systemType, BeehiveType beehiveType) { var beehive = new Beehive { ApiaryId = apiaryId, Number = number, SystemType = systemType, BeehiveType = beehiveType, IsAlive = true, }; await this.db.Beehives.AddAsync(beehive); await this.db.SaveChangesAsync(); AddSingleBeehiveToApiary(apiaryId, beehive); return(beehive.Id); }