public ActionResult EditSpreadsheet(TableModels model) { try { var userId = UserHelper.GetUserByEmail(User.Identity.Name).Id; if (ModelState.IsValid && IsUserAdmin(userId, model.Id)) { var dateTime = DateTime.Now; Repository<Model.TableModels> spreadsheetRepository = new Repository<Model.TableModels>(); var spreadsheet = spreadsheetRepository.Find(w => w.Id == model.Id); if (spreadsheet != null) { spreadsheet.Name = model.Name; } spreadsheetRepository.Commit(); long brandNewTable = spreadsheetRepository.Find(w => w.AuthorId_Id == userId && w.CreationDate == dateTime).Id; return RedirectToAction("Spreadsheet", new { id = brandNewTable }); } } catch (Exception) { } return RedirectToAction("ManageSpreadsheets"); }
public int AddNewSpreadsheet(string spreadsheetName) { try { if (ModelState.IsValid) { var userId = UserHelper.GetUserByEmail(User.Identity.Name).Id; if (spreadsheetRepository.Find(t => t.Name == spreadsheetName && t.AdministratorId_Id == userId) != null) { return 2; } var dateTime = DateTime.Now; string tableName = Guid.NewGuid().ToString(); string path = Server.MapPath(PathConstants.EmptyPath); string guidName = Server.MapPath(PathConstants.XlsPath) + tableName; if (path != null && !System.IO.File.Exists(guidName)) { System.IO.File.Create(guidName); Model.TableModels spreadsheet = new TableModels { Name = spreadsheetName, Content = System.IO.File.ReadAllBytes(path), CreationDate = dateTime, AdministratorId_Id = userId, AuthorId_Id = userId, SpreadsheetStatus = SpreadsheetStatusEnums.Active.ToString(), GuidName = guidName, DateOfLastChange = dateTime }; spreadsheetRepository.Add(spreadsheet); spreadsheetRepository.Commit(); var currentSpreadsheet = spreadsheetRepository.Find(w => w.AuthorId_Id == userId && w.CreationDate == dateTime); string hashCode = SHA1HashStringForUTF8String(User.Identity.Name + currentSpreadsheet.Id.ToString() + currentSpreadsheet.CreationDate.ToString()); currentSpreadsheet.HashCode = hashCode; spreadsheetRepository.Commit(); return 0; } } } catch (Exception) { } return 1; }
partial void DeleteTableModels(TableModels instance);
partial void UpdateTableModels(TableModels instance);
partial void InsertTableModels(TableModels instance);
private void detach_TableModels1(TableModels entity) { this.SendPropertyChanging(); entity.AspNetUsers1 = null; }
private void attach_TableModels(TableModels entity) { this.SendPropertyChanging(); entity.AspNetUsers = this; }