public async Task <IActionResult> Create(ConstructionWorksInputModel input)
        {
            if (!this.ModelState.IsValid)
            {
                return(this.View());
            }

            await this.constructionWorksService.CreateNewWorkAsync(input);

            return(this.Redirect("/ConstructionWorks/All"));
        }
Ejemplo n.º 2
0
        public async Task CreateNewWorkAsync(ConstructionWorksInputModel input)
        {
            ConstructionCategory category = this.context.ConstructionCategories.SingleOrDefault(x => x.Name == input.ConstructionCategory);

            MetricsType metric = this.context.MetricsTypes.SingleOrDefault(x => x.Name == input.Metric);

            ConstructionWork work = new ConstructionWork()
            {
                Title  = input.Title,
                Metric = metric,
                Price  = input.Price,
                ConstructionCategory = category,
            };

            await this.context.ConstructionWorks.AddAsync(work);

            await this.context.SaveChangesAsync();
        }