Esempio n. 1
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"));
        }
Esempio n. 2
0
        private async Task <long> SaveUserFile(long?fileId, IFormFile formFile, string name)
        {
            UserFileItem userFile = null;

            if (fileId != null)
            {
                userFile = _context.Files.FirstOrDefault(f => f.Id == fileId);
                string spath = Path.Combine(_hostingEnvironment.WebRootPath, "upload", userFile.ServerPath);
                System.IO.File.Move(spath, spath + ".deleted");
            }
            if (userFile == null)
            {
                userFile = new UserFileItem();
            }
            string serverFileName = Guid.NewGuid().ToString() + ".ufile";
            string serverPath     = Path.Combine(_hostingEnvironment.WebRootPath, "upload", serverFileName);

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

            fileToWrite.Close();

            userFile.TownId  = GroupItem.TownId;
            userFile.GroupId = GroupItem.Id;

            userFile.Visibility  = VisibilityType.CurrentGroup;
            userFile.FileName    = Path.GetFileName(formFile?.FileName);
            userFile.ContentType = formFile?.ContentType;
            userFile.ServerPath  = serverFileName;
            userFile.ClientPath  = formFile?.FileName;
            userFile.Size        = formFile?.Length ?? 0;
            userFile.Name        = name;
            userFile.Type        = Path.GetExtension(formFile?.FileName);


            if (fileId != null)
            {
                _context.Attach(userFile).State = EntityState.Modified;
            }
            else
            {
                _context.Add(userFile);
            }
            await _context.SaveChangesAsync();

            return(userFile.Id);
        }
Esempio n. 3
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)));
        }
Esempio n. 4
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)));
        }
Esempio n. 5
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)));
        }