public ActionResult Upload(UploadFileViewModel uploadFiles) { for (int i = 0; i < uploadFiles.Files.Count; i++) { var file = uploadFiles.Files[i]; if (file == null) { continue; } var fileName = Path.GetFileName(file.FileName); if (string.IsNullOrEmpty(fileName)) { return(RedirectToAction("Index")); } var ext = fileName.Substring(fileName.IndexOf(".")).ToLower(); if (ext == ".jpg" || ext == ".png" || ext == ".bmp") { if (file.ContentLength > 1000000) { continue; } } var newImage = new UserFile { OperationDate = _db.GetNzTime(), Operator = _currentUser.User.Email, FileType = ext, Category = uploadFiles.Category, Name = fileName }; _db.AddOneEntity(newImage); _db.SaveChange(); if (ext == ".jpg" || ext == ".png" || ext == ".bmp") { file.SaveAs(Server.MapPath("~/images/FileLibrary/" + newImage.Id + ext)); } else { file.SaveAs(Server.MapPath("~/images/FileLibrary/" + newImage.Name)); } } return(RedirectToAction <UploadFilesController>(d => d.Index(uploadFiles.Category))); }
public JsonResult _OperatorEdit(OperatorViewModel input) { _context.Get <ApplicationUser>(d => d.Id == input.Id).FirstOrDefault().UpdateDatetime = _context.GetNzTime(); var opteratorRoles = _context.Get <IdentityUserRole>(d => d.UserId == input.Id).ToList(); foreach (var item in opteratorRoles) { if (input.RolePosted != null) { if (!input.RolePosted.ids.Any(d => d == item.RoleId)) { var entity = _context.Get <IdentityUserRole>(d => d.RoleId == item.RoleId && d.UserId == input.Id).FirstOrDefault(); _context.GetTranscaiton().Entry(entity).State = EntityState.Deleted; } } else { var entity = _context.Get <IdentityUserRole>(d => d.RoleId == item.RoleId && d.UserId == input.Id).FirstOrDefault(); _context.GetTranscaiton().Entry(entity).State = EntityState.Deleted; } } _context.SaveChange(); if (input.RolePosted != null) { foreach (var item in input.RolePosted.ids) { if (!opteratorRoles.Any(d => d.RoleId == item)) { _context.AddOneEntity <IdentityUserRole>(new IdentityUserRole { UserId = input.Id, RoleId = item }); } } } return(Json("1", JsonRequestBehavior.AllowGet)); }