예제 #1
0
        public async Task <IActionResult> AddEntrance(EntranceInputModel entranceInputModel)
        {
            if (!this.ModelState.IsValid)
            {
                return(this.View(entranceInputModel));
            }

            try
            {
                await this.entrancesService.AddAsync(entranceInputModel);
            }
            catch (Exception)
            {
                return(this.View("DuplicateValue", entranceInputModel));
            }

            return(this.RedirectToAction("Index"));
        }
예제 #2
0
        public async Task AddAsync(EntranceInputModel entranceInputModel)
        {
            var entrance = new Entrance
            {
                EntranceAddressSign = entranceInputModel.EntranceAddressSign,
                BuildingId          = entranceInputModel.BuildingId,
            };

            bool doesEntranceExist = await this.entrancesRepository.All().AnyAsync(x => x.EntranceAddressSign == entrance.EntranceAddressSign);

            if (doesEntranceExist)
            {
                throw new ArgumentException(string.Format(GlobalConstants.ErrorMessages.EntranceAddressSignExists, entrance.EntranceAddressSign));
            }

            await this.entrancesRepository.AddAsync(entrance);

            await this.entrancesRepository.SaveChangesAsync();
        }