Example #1
0
        public async Task DeleteAsync(int id)
        {
            T domain = _TDbSet.Find(id);

            _TDbSet.Remove(domain);
            await _context.SaveChangesAsync();
        }
Example #2
0
        public async Task InsertMake(IVehicleMake vehicle)
        {
            VehicleMake create = mapper.Map <VehicleMake>(vehicle);

            context.VehicleMakes.Add(create);
            await context.SaveChangesAsync();
        }
Example #3
0
        public async Task <IActionResult> OnGetAsync(long?id)
        {
            if (id == null)
            {
                return(NotFound());
            }
            var uf = _context.Files.FirstOrDefault(t => t.Id == id);

            try
            {
                if (uf != null)
                {
                    var svrPath = System.IO.Path.Combine(_hostingEnvironment.WebRootPath, uf.ServerPath);
                    if (System.IO.File.Exists(svrPath))
                    {
                        FileStream fs = new FileStream(svrPath, FileMode.Open, FileAccess.Read);
                        uf.DownloadCount += 1;
                        _context.Files.Attach(uf).State = Microsoft.EntityFrameworkCore.EntityState.Modified;
                        await _context.SaveChangesAsync();

                        return(File(fs, uf.ContentType, uf.FileName));
                    }
                }
            }
            catch (Exception)
            {
            }
            return(NotFound());
        }
        public async Task <ActionResult <IEnumerable <string> > > PostAsync([FromBody] string name, string company, bool bike)
        {
            Debug.WriteLine("");
            Debug.WriteLine(name + company);
            Debug.WriteLine("");
            BaseFactory factory = new VehicleFactoryA();

            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            else if (bike)
            {
                var b = factory.CreateBike(name, company);
                b.Price = b.Price - (b.Price * 10 / 100); // 10% DISCOUNT AT factory A

                _context.Bikes.Add(b);
                await _context.SaveChangesAsync();

                return(CreatedAtAction("GetBike", new { id = b.ID }, b));
            }
            else
            {
                var b = factory.CreateCar(name, company);
                b.Price = b.Price - (b.Price * 15 / 100); // 15 % disc at Factory B
                _context.Cars.Add(b);
                await _context.SaveChangesAsync();

                return(CreatedAtAction("GetCar", new { id = b.ID }, b));
            }
        }
Example #5
0
        public async Task InsertModel(IVehicleModel vehicle)
        {
            VehicleModel create = mapper.Map <VehicleModel>(vehicle);

            context.VehicleModels.Add(create);
            await context.SaveChangesAsync();
        }
Example #6
0
        public async Task AddVehicle(Vehicle vehicle)
        {
            if (vehicle != null)
            {
                await _vehicleDbContext.Vehicles.AddAsync(vehicle);

                await _vehicleDbContext.SaveChangesAsync();
            }
        }
Example #7
0
        public async Task <IActionResult> Create([Bind("Id,Label")] Drive drive)
        {
            if (ModelState.IsValid)
            {
                _context.Add(drive);
                await _context.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }
            return(View(drive));
        }
Example #8
0
        public async Task <IActionResult> Create([Bind("Id,CylindersId,Displacement,DriveId,FuelCost,FuelTypeId,MakeId,Model,TransmissionId,CityMilage,HighwayMilage,VehicleClassId,YearId")] Vehicle vehicle)
        {
            if (ModelState.IsValid)
            {
                _context.Add(vehicle);
                await _context.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }
            ViewData["CylindersId"] = new SelectList(_context.Cylinders, "Id", "Id", vehicle.CylindersId);
            return(View(vehicle));
        }
        private async Task <AuthenticationResult> GenerateAuthenticationResultForUserAsync(CustomUser user)
        {
            var jwtSecurityTokenHandler = new JwtSecurityTokenHandler();
            var jwtSecretBytesKey       = Encoding.ASCII.GetBytes(_jwtSettings.Secret);

            var claims = new List <Claim>
            {
                new Claim(JwtRegisteredClaimNames.Sub, user.Email),
                new Claim(JwtRegisteredClaimNames.Jti, Guid.NewGuid().ToString()),
                new Claim(JwtRegisteredClaimNames.Email, user.Email),
                new Claim("id", user.Id)
            };

            var userClaims = await _userManager.GetClaimsAsync(user);

            claims.AddRange(userClaims);

            (claims, user) = await AddRolesAndRoleClaimsAsync(claims, user);

            var tokenDescriptor = new SecurityTokenDescriptor
            {
                Subject            = new ClaimsIdentity(claims),
                Expires            = DateTime.UtcNow.Add(_jwtSettings.TokenLifetime),//differece here! now 30 seconds
                SigningCredentials =
                    new SigningCredentials(
                        new SymmetricSecurityKey(jwtSecretBytesKey),
                        SecurityAlgorithms.HmacSha256Signature)
            };

            var tokenFromTokenDescriptor = jwtSecurityTokenHandler.CreateToken(tokenDescriptor);

            var refreshTokenForUser = new RefreshToken
            {
                JwtId        = tokenFromTokenDescriptor.Id,
                UserId       = user.Id,
                CreationDate = DateTime.UtcNow,
                ExpiryDate   = DateTime.UtcNow.AddMonths(6)//6 months to expire
            };

            await _context.RefreshTokens.AddAsync(refreshTokenForUser);

            await _context.SaveChangesAsync();

            return(new AuthenticationResult
            {
                Success = true,
                Token = jwtSecurityTokenHandler.WriteToken(tokenFromTokenDescriptor),
                RefreshToken = refreshTokenForUser.Token
            });
        }
Example #10
0
        public async Task <IActionResult> OnPostAsync()
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }

            _context.Attach(SecurityPerson).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!SecurityPersonExists(SecurityPerson.Id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(RedirectToPage("./Index"));
        }
Example #11
0
        // Make
        public async Task <ActionResult <VehicleMake> > CreateVehicleMake(VehicleMake newVehicleMake)
        {
            _context.VehicleMakes.Add(newVehicleMake);
            await _context.SaveChangesAsync();

            return(newVehicleMake);
        }
        // Makes
        public async Task <ActionResult <CreateMakeDto> > CreateVehicleMake(CreateMakeDto newVehicleMake)
        {
            var newMakeEntity = Mapping.Mapper.Map <VehicleMake>(newVehicleMake);

            _context.VehicleMakes.Add(newMakeEntity);
            await _context.SaveChangesAsync();

            return(newVehicleMake);
        }
Example #13
0
        public async Task <IActionResult> OnPostAsync()
        {
            if (!ModelState.IsValid)
            {
                var townlist = (await _townService.GetAvailableTownsEagerAsync(HttpContext.User));

                ViewData["TownList"] = new SelectList(townlist, "Id", "Name");
                if (townlist.Any())
                {
                    var groups = (await _groupService.ListGroupsForTownEagerAsync(HttpContext.User, townlist.First().Id));
                    ViewData["GroupList"] = new SelectList(groups, "Id", "Name");
                }

                return(Page());
            }

            var user = await _userManager.GetUserAsync(HttpContext.User);



            var vehicle = _context.Vehicles.FirstOrDefault(v => v.Id == VehicleItem.Id);

            if (vehicle == null)
            {
                return(NotFound());
            }
            await VehicleItem.FillVehicleItem(vehicle);

            vehicle.FrontImage   = VehicleItem.PhotoFront.UpdateUserFile(vehicle.FrontImage, _context, VisibilityType.CurrentVehicle, "车头部照片", VehicleItem.TownId, VehicleItem.GroupId);
            vehicle.RearImage    = VehicleItem.PhotoRear.UpdateUserFile(vehicle.RearImage, _context, VisibilityType.CurrentVehicle, "车尾部照片", VehicleItem.TownId, VehicleItem.GroupId);
            vehicle.GpsImage     = VehicleItem.PhotoGps.UpdateUserFile(vehicle.GpsImage, _context, VisibilityType.CurrentVehicle, "GPS照片", VehicleItem.TownId, VehicleItem.GroupId);
            vehicle.LicenseImage = VehicleItem.PhotoLicense.UpdateUserFile(vehicle.LicenseImage, _context, VisibilityType.CurrentVehicle, "行驶证照片", VehicleItem.TownId, VehicleItem.GroupId);
            vehicle.ExtraImage1  = VehicleItem.ExtraPhoto1.UpdateUserFile(vehicle.ExtraImage1, _context, VisibilityType.CurrentVehicle, "附加图片1", VehicleItem.TownId, VehicleItem.GroupId);
            vehicle.ExtraImage2  = VehicleItem.ExtraPhoto2.UpdateUserFile(vehicle.ExtraImage2, _context, VisibilityType.CurrentVehicle, "附加图片2", VehicleItem.TownId, VehicleItem.GroupId);
            vehicle.ExtraImage3  = VehicleItem.ExtraPhoto3.UpdateUserFile(vehicle.ExtraImage3, _context, VisibilityType.CurrentVehicle, "附加图片1", VehicleItem.TownId, VehicleItem.GroupId);

            vehicle.ModifyBy         = user.Id;
            vehicle.ModificationDate = DateTime.Now;
            vehicle.Status           = StatusType.OK;
            vehicle.VersionNumber   += 1;


            _context.Entry(vehicle).State = EntityState.Modified;
            await _context.SaveChangesAsync();

            return(Redirect(Url.GetLocalUrl(ReturnUrl)));
        }
Example #14
0
        public async Task <IActionResult> OnPostAsync(long?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            VehicleItem = await _context.Vehicles.FindAsync(id);

            if (VehicleItem != null)
            {
                _context.Vehicles.Remove(VehicleItem);
                await _context.SaveChangesAsync();
            }

            return(Redirect(Url.GetLocalUrl(ReturnUrl)));
        }
Example #15
0
        public async Task <bool> Add(Cart cart)
        {
            try
            {
                _log4net.Info(nameof(CartOperations) + "invoked");

                context.Carts.Add(cart);
                int a = await context.SaveChangesAsync();

                return(a == 1);
            }
            catch (Exception e)
            {
                _log4net.Error("Error occured from " + nameof(CartOperations) + "Error Message " + e.Message);
                return(false);
            }
        }
        public async Task <bool> Add(User user)
        {
            try
            {
                _log4net.Info(nameof(UserOperations) + "invoked");

                vehicleDbContext.Users.Add(user);
                int a = await vehicleDbContext.SaveChangesAsync();

                return(a == 1);
            }
            catch (Exception e)
            {
                _log4net.Error("Error occured from " + nameof(UserOperations) + "Error Message " + e.Message);
                return(false);
            }
        }
Example #17
0
        public async Task <IActionResult> OnPostAsync()
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }

            try
            {
                var    subfolder      = (DateTime.Now.Second % 10).ToString();
                string serverFileName = Guid.NewGuid().ToString() + ".ufile";
                string serverPath     = Path.Combine(_hostingEnvironment.WebRootPath, "upload", subfolder, serverFileName);

                FileStream fileToWrite = new FileStream(serverPath, FileMode.Create, FileAccess.Write);
                await UserFile.UploadFile.CopyToAsync(fileToWrite);

                fileToWrite.Close();
                var ufile = new UserFileItem()
                {
                    TownId      = UserFile.TownId,
                    GroupId     = UserFile.GroupId,
                    Visibility  = UserFile.Visibility,
                    FileName    = Path.GetFileName(UserFile.UploadFile?.FileName),
                    ContentType = UserFile.UploadFile?.ContentType,
                    ServerPath  = Path.Combine("upload", subfolder, serverFileName),
                    ClientPath  = UserFile.UploadFile?.FileName,
                    Size        = UserFile.UploadFile?.Length ?? 0,
                    Name        = UserFile.Name,
                    Type        = Path.GetExtension(UserFile.UploadFile?.FileName),

                    CreationDate = DateTime.Now,
                };



                _context.Files.Add(ufile);
                await _context.SaveChangesAsync();

                return(Redirect(Url.GetLocalUrl(ReturnUrl)));
            }
            catch (Exception)
            {
                return(NotFound());
            }
        }
        public async Task <IActionResult> CreateVehicle([FromBody] VehicleResource vehicleResource)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var vehicle = mapper.Map <VehicleResource, Vehicle>(vehicleResource);

            vehicle.LastUpdate = DateTime.Now;

            context.Vehicles.Add(vehicle);
            await context.SaveChangesAsync();

            var result = mapper.Map <Vehicle, VehicleResource>(vehicle);

            return(Ok(result));
        }
Example #19
0
        public async Task <IActionResult> OnPostAsync(long?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            UserFile = await _context.Files.FindAsync(id);

            if (UserFile != null)
            {
                UserFile.DeleteFromServer();
                UserFile.Status = StatusType.Deleted;
                await _context.SaveChangesAsync();
            }

            return(Redirect(Url.GetLocalUrl(ReturnUrl)));
        }
Example #20
0
        public async Task <IActionResult> OnPostAsync()
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }

            var user = await _userManager.GetUserAsync(HttpContext.User);


            var news = _context.Newses.FirstOrDefault(v => v.Id == NewsItem.Id);

            if (news == null)
            {
                return(NotFound());
            }
            await NewsItem.FillNewsItem(news);

            news.ImageFile              = NewsItem.Image.UpdateUserFile(news.ImageFile, _context, VisibilityType.CurrentNews, "新闻图片");
            news.ModificationDate       = DateTime.Now;
            news.ModifyBy               = user.Id;
            news.VersionNumber         += 1;
            _context.Attach(news).State = EntityState.Modified;


            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!NewsItemExists(NewsItem.Id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(Redirect(Url.GetLocalUrl(ReturnUrl)));
        }
Example #21
0
        public async Task <IActionResult> OnPostAsync()
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }


            var user = await _userManager.GetUserAsync(HttpContext.User);

            var news = new NewsItem();
            await NewsItem.FillNewsItem(news);

            news.ImageFile     = NewsItem.Image.UpdateUserFile(news.ImageFile, _context, VisibilityType.CurrentNews, "新闻图片");
            news.CreationDate  = DateTime.Now;
            news.CreateBy      = user.Id;
            news.VersionNumber = 1;

            _context.Newses.Add(news);
            await _context.SaveChangesAsync();

            return(Redirect(Url.GetLocalUrl(ReturnUrl)));
        }
Example #22
0
 public async Task <int> CompleteAsync()
 {
     return(await context.SaveChangesAsync());
 }
Example #23
0
 public async Task SaveChangesAsync() => await dbContext.SaveChangesAsync();
Example #24
0
 public Task <int> Add(Vehicle vehicle)
 {
     _dbContext.Vehicles.Add(vehicle);
     return(_dbContext.SaveChangesAsync());
 }
 public async Task <int> SaveChangesAsync()
 {
     return(await _dbContext.SaveChangesAsync());
 }
        public async Task <int> AddAsync(TEntity entity)
        {
            _vehicleDbContext.Set <TEntity>().Add(entity);

            return(await _vehicleDbContext.SaveChangesAsync());
        }
Example #27
0
        public async Task <IActionResult> OnPostAsync()
        {
            if (!ModelState.IsValid)
            {
                ViewData["TownList"] = (await _townService.GetAvailableTownsEagerAsync(HttpContext.User))
                                       .Select(t => new SelectListItem {
                    Value = t.Id.ToString(), Text = t.Name,
                })
                                       .ToList();
                return(Page());
            }
            var user = await _userManager.GetUserAsync(HttpContext.User);



            var group = new GroupItem()
            {
                CreationDate = DateTime.Now,
                CreateBy     = user.Id,
                Status       = StatusType.OK,
            };

            var canEdit = _authorizationService.AuthorizeAsync(HttpContext.User, group, "CanEdit");

            if (!(await canEdit).Succeeded)
            {
                return(Unauthorized());
            }


            await GroupItem.FillGroupItem(group);

            if (GroupItem.MainImage != null)
            {
                group.MainImage = GroupItem.MainImage.ToUserFile("企业图片");
                _context.Files.Add(group.MainImage);
            }
            if (GroupItem.LicenseImage != null)
            {
                group.LicenseImage = GroupItem.LicenseImage.ToUserFile("证照图片");
                _context.Files.Add(group.LicenseImage);
            }
            if (GroupItem.ExtraPhoto1 != null)
            {
                group.ExtraImage1 = GroupItem.ExtraPhoto1.ToUserFile("附加图片1");
                _context.Files.Add(group.ExtraImage1);
            }
            if (GroupItem.ExtraPhoto2 != null)
            {
                group.ExtraImage2 = GroupItem.ExtraPhoto2.ToUserFile("附加图片2");
                _context.Files.Add(group.ExtraImage2);
            }
            if (GroupItem.ExtraPhoto3 != null)
            {
                group.ExtraImage3 = GroupItem.ExtraPhoto3.ToUserFile("附加图片3");
                _context.Files.Add(group.ExtraImage3);
            }
            if (GroupItem.ApplicationFile != null)
            {
                group.ApplicationFile = GroupItem.ApplicationFile.ToUserFile("安全组审批表");
                _context.Files.Add(group.ApplicationFile);
            }
            if (GroupItem.RuleFile != null)
            {
                group.RuleFile = GroupItem.RuleFile.ToUserFile("规章制度");
                _context.Files.Add(group.RuleFile);
            }
            if (GroupItem.GroupGuranteeFile != null)
            {
                group.GroupGuranteeFile = GroupItem.GroupGuranteeFile.ToUserFile("安全组责任状");
                _context.Files.Add(group.GroupGuranteeFile);
            }
            if (GroupItem.DriverGuranteeFile != null)
            {
                group.DriverGuranteeFile = GroupItem.DriverGuranteeFile.ToUserFile("安全组责任状");
                _context.Files.Add(group.DriverGuranteeFile);
            }
            _context.Groups.Add(group);

            await _context.SaveChangesAsync();

            if (GroupItem.MainImage != null)
            {
                group.MainImage.GroupId               = group.Id;
                group.MainImage.TownId                = group.TownId;
                group.MainImage.Visibility            = VisibilityType.CurrentGroup;
                _context.Entry(group.MainImage).State = EntityState.Modified;
            }
            if (GroupItem.LicenseImage != null)
            {
                group.LicenseImage.GroupId               = group.Id;
                group.LicenseImage.TownId                = group.TownId;
                group.LicenseImage.Visibility            = VisibilityType.CurrentGroup;
                _context.Entry(group.LicenseImage).State = EntityState.Modified;
            }
            if (GroupItem.ExtraPhoto1 != null)
            {
                group.ExtraImage1.GroupId               = group.Id;
                group.ExtraImage1.TownId                = group.TownId;
                group.ExtraImage1.Visibility            = VisibilityType.CurrentGroup;
                _context.Entry(group.ExtraImage1).State = EntityState.Modified;
            }
            if (GroupItem.ExtraPhoto2 != null)
            {
                group.ExtraImage2.GroupId               = group.Id;
                group.ExtraImage2.TownId                = group.TownId;
                group.ExtraImage2.Visibility            = VisibilityType.CurrentGroup;
                _context.Entry(group.ExtraImage2).State = EntityState.Modified;
            }
            if (GroupItem.ExtraPhoto3 != null)
            {
                group.ExtraImage3.GroupId               = group.Id;
                group.ExtraImage3.TownId                = group.TownId;
                group.ExtraImage3.Visibility            = VisibilityType.CurrentGroup;
                _context.Entry(group.ExtraImage3).State = EntityState.Modified;
            }
            if (GroupItem.ApplicationFile != null)
            {
                group.ApplicationFile.GroupId               = group.Id;
                group.ApplicationFile.TownId                = group.TownId;
                group.ApplicationFile.Visibility            = VisibilityType.CurrentGroup;
                _context.Entry(group.ApplicationFile).State = EntityState.Modified;
            }
            if (GroupItem.RuleFile != null)
            {
                group.RuleFile.GroupId               = group.Id;
                group.RuleFile.TownId                = group.TownId;
                group.RuleFile.Visibility            = VisibilityType.CurrentGroup;
                _context.Entry(group.RuleFile).State = EntityState.Modified;
            }
            if (GroupItem.GroupGuranteeFile != null)
            {
                group.GroupGuranteeFile.GroupId               = group.Id;
                group.GroupGuranteeFile.TownId                = group.TownId;
                group.GroupGuranteeFile.Visibility            = VisibilityType.CurrentGroup;
                _context.Entry(group.GroupGuranteeFile).State = EntityState.Modified;
            }
            if (GroupItem.DriverGuranteeFile != null)
            {
                group.DriverGuranteeFile.GroupId               = group.Id;
                group.DriverGuranteeFile.TownId                = group.TownId;
                group.DriverGuranteeFile.Visibility            = VisibilityType.CurrentGroup;
                _context.Entry(group.DriverGuranteeFile).State = EntityState.Modified;
            }
            await _context.SaveChangesAsync();


            return(Redirect(Url.GetLocalUrl(ReturnUrl)));
        }
Example #28
0
        public async Task <IActionResult> OnPostAsync()
        {
            if (!ModelState.IsValid)
            {
                var townlist = (await _townService.GetAvailableTownsEagerAsync(HttpContext.User));

                ViewData["TownList"] = new SelectList(townlist, "Id", "Name");
                if (townlist.Any())
                {
                    var groups = (await _groupService.ListGroupsForTownEagerAsync(HttpContext.User, townlist.First().Id));
                    ViewData["GroupList"] = new SelectList(groups, "Id", "Name");
                }


                return(Page());
            }


            var user = await _userManager.GetUserAsync(HttpContext.User);



            var townId = await _userManager.IsInRoleAsync(user, "TownManager") ? user.TownId : DriverItem.TownId;

            var driver = _context.Drivers.FirstOrDefault(t => t.Id == DriverItem.Id);

            if (driver == null)
            {
                return(NotFound());
            }

            driver.Name   = DriverItem.Name;
            driver.Gender = DriverItem.Gender;
            driver.FirstLicenseIssueDate = DriverItem.FirstLicenseIssueDate;
            driver.LicenseIssueDate      = DriverItem.LicenseIssue;

            driver.IdCardNumber      = DriverItem.IdCardNumber;
            driver.LicenseNumber     = DriverItem.License;
            driver.LicenseType       = DriverItem.LicenseType;
            driver.LicenseValidYears = DriverItem.ValidYears;
            driver.LivingAddress     = DriverItem.LivingAddress;
            driver.Tel          = DriverItem.Tel;
            driver.Title        = DriverItem.Title;
            driver.WarrantyCode = DriverItem.WarrantyCode;
            driver.ResidentType = DriverItem.ResidentType;

            driver.TownId  = townId;
            driver.GroupId = DriverItem.GroupId;

            driver.IdCardImage1 = DriverItem.PhotoIdCard1.UpdateUserFile(driver.IdCardImage1, _context, VisibilityType.CurrentDriver, "身份证国徽面图片", DriverItem.TownId, DriverItem.GroupId);
            driver.IdCardImage2 = DriverItem.PhotoIdCard2.UpdateUserFile(driver.IdCardImage2, _context, VisibilityType.CurrentDriver, "身份证相片面图片", DriverItem.TownId, DriverItem.GroupId);
            driver.LicenseImage = DriverItem.PhotoDriverLicense.UpdateUserFile(driver.LicenseImage, _context, VisibilityType.CurrentDriver, "驾驶证照片", DriverItem.TownId, DriverItem.GroupId);
            driver.AvatarImage  = DriverItem.PhotoAvatar.UpdateUserFile(driver.AvatarImage, _context, VisibilityType.CurrentDriver, "驾驶员图片", DriverItem.TownId, DriverItem.GroupId);
            driver.ExtraImage1  = DriverItem.ExtraImage1.UpdateUserFile(driver.ExtraImage1, _context, VisibilityType.CurrentDriver, "附加图片1", DriverItem.TownId, DriverItem.GroupId);
            driver.ExtraImage2  = DriverItem.ExtraImage2.UpdateUserFile(driver.ExtraImage2, _context, VisibilityType.CurrentDriver, "附加图片2", DriverItem.TownId, DriverItem.GroupId);
            driver.ExtraImage3  = DriverItem.ExtraImage3.UpdateUserFile(driver.ExtraImage3, _context, VisibilityType.CurrentDriver, "附加图片3", DriverItem.TownId, DriverItem.GroupId);

            driver.ModifyBy               = user.Id;
            driver.ModificationDate       = DateTime.Now;
            driver.Status                 = StatusType.OK;
            driver.VersionNumber         += 1;
            _context.Attach(driver).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!DriverItemExists(DriverItem.Id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(Redirect(Url.GetLocalUrl(ReturnUrl)));
        }
Example #29
0
        public async Task <IActionResult> OnPostAsync()
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }

            var group = _context.Groups.Include(t => t.MainImage).FirstOrDefault(t => t.Id == GroupItem.Id);

            if (group == null)
            {
                return(NotFound());
            }

            var canEdit = _authorizationService.AuthorizeAsync(HttpContext.User, group, "CanEdit");

            if (!(await canEdit).Succeeded)
            {
                return(Unauthorized());
            }

            await GroupItem.FillGroupItem(group);

            if (GroupItem.MainImage != null)
            {
                if (group.MainImage?.Status == StatusType.OK)
                {
                    group.MainImage.DeleteFromServer();
                    group.MainImage.Status = StatusType.Deleted;
                    _context.Entry(group.MainImage).State = EntityState.Modified;
                }
                group.MainImage            = GroupItem.MainImage.ToUserFile("企业图片");
                group.MainImage.GroupId    = group.Id;
                group.MainImage.TownId     = group.TownId;
                group.MainImage.Visibility = VisibilityType.CurrentGroup;
                _context.Files.Add(group.MainImage);
            }
            if (GroupItem.LicenseImage != null)
            {
                if (group.LicenseImage?.Status == StatusType.OK)
                {
                    group.LicenseImage.DeleteFromServer();
                    group.LicenseImage.Status = StatusType.Deleted;
                    _context.Entry(group.LicenseImage).State = EntityState.Modified;
                }
                group.LicenseImage            = GroupItem.LicenseImage.ToUserFile("证照图片");
                group.LicenseImage.GroupId    = group.Id;
                group.LicenseImage.TownId     = group.TownId;
                group.LicenseImage.Visibility = VisibilityType.CurrentGroup;
                _context.Files.Add(group.LicenseImage);
            }
            if (GroupItem.ExtraPhoto1 != null)
            {
                if (group.ExtraImage1?.Status == StatusType.OK)
                {
                    group.ExtraImage1.DeleteFromServer();
                    group.ExtraImage1.Status = StatusType.Deleted;
                    _context.Entry(group.ExtraImage1).State = EntityState.Modified;
                }
                group.ExtraImage1            = GroupItem.ExtraPhoto1.ToUserFile("附加图片1");
                group.ExtraImage1.GroupId    = group.Id;
                group.ExtraImage1.TownId     = group.TownId;
                group.ExtraImage1.Visibility = VisibilityType.CurrentGroup;
                _context.Files.Add(group.ExtraImage1);
            }
            if (GroupItem.ExtraPhoto2 != null)
            {
                if (group.ExtraImage2?.Status == StatusType.OK)
                {
                    group.ExtraImage2.DeleteFromServer();
                    group.ExtraImage2.Status = StatusType.Deleted;
                    _context.Entry(group.ExtraImage2).State = EntityState.Modified;
                }
                group.ExtraImage2            = GroupItem.ExtraPhoto2.ToUserFile("附加图片2");
                group.ExtraImage2.GroupId    = group.Id;
                group.ExtraImage2.TownId     = group.TownId;
                group.ExtraImage2.Visibility = VisibilityType.CurrentGroup;
                _context.Files.Add(group.ExtraImage2);
            }
            if (GroupItem.ExtraPhoto3 != null)
            {
                if (group.ExtraImage3?.Status == StatusType.OK)
                {
                    group.ExtraImage3.DeleteFromServer();
                    group.ExtraImage3.Status = StatusType.Deleted;
                    _context.Entry(group.ExtraImage3).State = EntityState.Modified;
                }
                group.ExtraImage3            = GroupItem.ExtraPhoto3.ToUserFile("附加图片3");
                group.ExtraImage3.GroupId    = group.Id;
                group.ExtraImage3.TownId     = group.TownId;
                group.ExtraImage3.Visibility = VisibilityType.CurrentGroup;
                _context.Files.Add(group.ExtraImage3);
            }
            if (GroupItem.ApplicationFile != null)
            {
                if (group.ApplicationFile?.Status == StatusType.OK)
                {
                    group.ApplicationFile.DeleteFromServer();
                    group.ApplicationFile.Status = StatusType.Deleted;
                    _context.Entry(group.ApplicationFile).State = EntityState.Modified;
                }
                group.ApplicationFile            = GroupItem.ApplicationFile.ToUserFile("安全组审批表");
                group.ApplicationFile.GroupId    = group.Id;
                group.ApplicationFile.TownId     = group.TownId;
                group.ApplicationFile.Visibility = VisibilityType.CurrentGroup;
                _context.Files.Add(group.ApplicationFile);
            }
            if (GroupItem.RuleFile != null)
            {
                if (group.RuleFile?.Status == StatusType.OK)
                {
                    group.RuleFile.DeleteFromServer();
                    group.RuleFile.Status = StatusType.Deleted;
                    _context.Entry(group.RuleFile).State = EntityState.Modified;
                }
                group.RuleFile            = GroupItem.RuleFile.ToUserFile("规章制度");
                group.RuleFile.GroupId    = group.Id;
                group.RuleFile.TownId     = group.TownId;
                group.RuleFile.Visibility = VisibilityType.CurrentGroup;
                _context.Files.Add(group.RuleFile);
            }
            if (GroupItem.GroupGuranteeFile != null)
            {
                if (group.GroupGuranteeFile?.Status == StatusType.OK)
                {
                    group.GroupGuranteeFile.DeleteFromServer();
                    group.GroupGuranteeFile.Status = StatusType.Deleted;
                    _context.Entry(group.GroupGuranteeFile).State = EntityState.Modified;
                }
                group.GroupGuranteeFile            = GroupItem.GroupGuranteeFile.ToUserFile("安全组责任状");
                group.GroupGuranteeFile.GroupId    = group.Id;
                group.GroupGuranteeFile.TownId     = group.TownId;
                group.GroupGuranteeFile.Visibility = VisibilityType.CurrentGroup;
                _context.Files.Add(group.GroupGuranteeFile);
            }
            if (GroupItem.DriverGuranteeFile != null)
            {
                if (group.DriverGuranteeFile?.Status == StatusType.OK)
                {
                    group.DriverGuranteeFile.DeleteFromServer();
                    group.DriverGuranteeFile.Status = StatusType.Deleted;
                    _context.Entry(group.DriverGuranteeFile).State = EntityState.Modified;
                }
                group.DriverGuranteeFile            = GroupItem.DriverGuranteeFile.ToUserFile("驾驶员责任状");
                group.DriverGuranteeFile.GroupId    = group.Id;
                group.DriverGuranteeFile.TownId     = group.TownId;
                group.DriverGuranteeFile.Visibility = VisibilityType.CurrentGroup;
                _context.Files.Add(group.DriverGuranteeFile);
            }

            group.ModificationDate = DateTime.Now;
            group.ModifyBy         = (await _userManager.GetUserAsync(HttpContext.User)).Id;
            group.Status           = StatusType.OK;
            group.VersionNumber   += 1;

            _context.Attach(group).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!GroupItemExists(GroupItem.Id))
                {
                    return(this.NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(Redirect(Url.GetLocalUrl(ReturnUrl)));
        }
Example #30
0
 public async Task <int> AddAsync(TModel entity)
 {
     dbContext.Set <TModel>().Add(entity);
     return(await dbContext.SaveChangesAsync());
 }