Exemple #1
0
        public async Task <int> AddInstrumentTypeAsync(AddInstrumentTypeBindingModel model)
        {
            var existingType = this.DbContext
                               .InstrumentTypes
                               .FirstOrDefault(x => x.TypeName == model.TypeName);

            if (existingType != null)
            {
                return(ErrorId);
            }

            var type = this.Mapper.Map <InstrumentType>(model);

            await this.DbContext.InstrumentTypes.AddAsync(type);

            await this.DbContext.SaveChangesAsync();

            return(type.Id);
        }
        public async Task <IActionResult> AddInstrumentType(AddInstrumentTypeBindingModel model)
        {
            if (!this.ModelState.IsValid)
            {
                SetErrorMessage(CommonConstants.DangerMessage);

                return(this.AddInstrumentType());
            }

            int generatedId = await this.instrumentService.AddInstrumentTypeAsync(model);

            if (generatedId < 1)
            {
                SetErrorMessage(CommonConstants.DuplicateMessage);

                return(this.AddInstrumentType());
            }

            SetSuccessMessage(string.Format(CommonConstants.SuccessMessage, CommonConstants.InstrumentTypeDisplay));

            return(RedirectToAction(RedirectConstants.InstrumentTypeDetailsSuffix, RedirectConstants.InstrumentsSuffix, generatedId));
        }