コード例 #1
0
        private async Task <TypeMakerEntity> CkeckTypeMakerAsync(BikeMakerEntity maker, BikeTypeEntity type)
        {
            var TypeMake = new TypeMakerEntity
            {
                BikeMaker = maker,
                BikeType  = type,
            };

            await _dataContext.TypeMakers.AddAsync(TypeMake);

            await _dataContext.SaveChangesAsync();

            return(TypeMake);
        }
コード例 #2
0
        public async Task <IActionResult> EditType(TypeMakerViewModel model)
        {
            model.BikeMaker = await _context.BikeMakers.FindAsync(model.MakerId);

            model.BikeType = await _context.BikeTypes.FindAsync(model.TypeId);

            if (model.BikeMaker == null)
            {
                model.Types = _combosHelper.GetComboTypes();
                return(View(model));
            }

            if (model.BikeType == null)
            {
                model.Types = _combosHelper.GetComboTypes();
                return(View(model));
            }


            var path = model.ImageUrl;

            if (model.ImageFile != null)
            {
                path = await _imageHelper.UploadImageAsync(model.ImageFile, "BikeTypes");
            }

            var typeMakerEntity = new TypeMakerEntity
            {
                Id        = model.Id,
                ImageUrl  = path,
                BikeMaker = await _context.BikeMakers.FindAsync(model.MakerId),
                BikeType  = await _context.BikeTypes.FindAsync(model.TypeId)
            };

            try
            {
                _context.TypeMakers.Update(typeMakerEntity);
                await _context.SaveChangesAsync();
            }
            catch (Exception err)
            {
                return(RedirectToAction($"Details/{model.MakerId}", new RouteValueDictionary(new { Controller = "BikeMakers", err.Message })));
            }

            return(RedirectToAction($"Details/{model.MakerId}"));
        }
コード例 #3
0
        private async Task <MotorBikeEntity> CheckMotorBikeAsync(string name, int cylinder, bool millimeters,
                                                                 int orgw_ft, int orgh_ft, int fronttire, int orgw_rt, int orgh_rt, int reartire, TypeMakerEntity typeMaker)
        {
            var motorbike = new MotorBikeEntity
            {
                Name            = name,
                Cylinder        = cylinder,
                Millimeters     = millimeters,
                WidthTireF      = orgw_ft,
                HeightTireF     = orgh_ft,
                FrontTire       = fronttire,
                WidthTireR      = orgw_rt,
                HeightTireR     = orgh_rt,
                RearTire        = reartire,
                TypeMaker       = typeMaker,
                MotorBikeSpares = new List <MotorBikeSpareEntity>(),
            };
            await _dataContext.MotorBikes.AddAsync(motorbike);

            await _dataContext.SaveChangesAsync();

            return(motorbike);
        }