public ActionResult AddDocument(AddDocumentViewModel model) { if (ModelState.IsValid) { if (model.File == null || model.File.ContentLength == 0) { return View(); } try { var user = UserManager.FindById(this.GetUserId()); Guid publicKey = Guid.NewGuid(); CloudStorageMananger storage = new CloudStorageMananger(this.DBContext); var cloudStorageItem = storage.UploadFromStream( user.DefaultContainer.CloudStorageAccount.AccountName, user.DefaultContainer.CloudStorageAccount.AccountKey, user.DefaultContainer.ContainerName, this.GetUserId(), User.Identity.Name, model.File.FileName, model.File.ContentType, model.File.InputStream, model.DocumentName, model.Description); var item = new DriveItem(cloudStorageItem); item.OwnerId = this.GetUserId(); item.CloudStorageItem.CloudStorageContainerId = (int)user.DefaultContainerId; this.DBContext.DriveItems.Add(item); this.DBContext.SaveChanges(); } catch (Exception ex) { //log.Error(ex, "Error upload photo blob to storage"); ex.ToString(); } } return RedirectToAction("Index", "Home"); }
// GET: CloudStorageContainer public ActionResult Index() { ApplicationDbContext context = new ApplicationDbContext(); var user = context.Users.Find(User.Identity.GetUserId()); var account = user.CloudStorageAccounts.FirstOrDefault(); var container = account.CloudStorageContainers.FirstOrDefault(); // CloudStorageMananger.GetBlobs(); CloudStorageMananger storage = new CloudStorageMananger(context); var itemList = storage.GetCloudStorageItems(); CloudStorageContainerListModel model = new CloudStorageContainerListModel { Container = container, CloudStorageItems = itemList // blobNames }; return View(model); }
//public HomeDetailViewModel() { //} public HomeDetailViewModel(CloudStorageMananger manager) { this.manager = manager; }
public async Task<ActionResult> ConfirmEmail(string invitation, string code) { //public async Task<ActionResult> ConfirmEmail(string userId, string code) { if (invitation == null || code == null) { return View("Error"); } //IdentityResult result; //try { // result = await UserManager.ConfirmEmailAsync(userId, code); //} //catch (InvalidOperationException ioe) { // // ConfirmEmailAsync throws when the userId is not found. // ViewBag.errorMessage = ioe.Message; // return View("Error"); //} //if (result.Succeeded) { // return View(); //} //// If we got this far, something failed. //AddErrors(result); //ViewBag.errorMessage = "ConfirmEmail failed"; //return View("Error"); var invId = Guid.Parse(invitation); var user = UserManager.Users.SingleOrDefault(u => u.PublicKey == invId); if (user == null) { return View("Error"); } var result = await UserManager.ConfirmEmailAsync(user.Id, code); if (result.Succeeded) { string containerId = user.PublicKey.ToString("N"); CloudStorageMananger manager = new CloudStorageMananger(DBContext); CloudStorageContainer container = manager.CreateContainer("Azure", user.PublicKey, user.UserName, string.Format("{0}'s default storage container", user.UserName)); user.DefaultContainer = container; UserManager.Update(user); } return View(result.Succeeded ? "ConfirmEmail" : "Error"); //if (result.Succeeded) // return View("ConfirmEmail"); //AddErrors(result); //return View("Error"); }
public string GetTempUrl(CloudStorageMananger manager) { return manager.GetTempUrl(this.CloudStorageContainer.CloudStorageAccount.AccountName, this.CloudStorageContainer.CloudStorageAccount.AccountKey, this.Url); }
public ActionResult AddDocument(AddDocumentViewModel model) { if (ModelState.IsValid) { string fullPath = null; if (model.File == null || model.File.ContentLength == 0) { return View(); } try { CloudStorageMananger storage = new CloudStorageMananger(); storage.UploadFromStream(User.Identity.GetUserId(), User.Identity.Name, model.File.FileName, model.File.ContentType, model.File.InputStream, model.DocumentName, model.Description); //string fileName = UploadFile.UploadFileToPrivateContainer(model.File); //if (!string.IsNullOrEmpty(userId)) { // var user = UserManager.FindById(userId); // blockBlob.Metadata.Add("username", user.UserName); //} } catch (Exception ex) { //log.Error(ex, "Error upload photo blob to storage"); ex.ToString(); } // using (var db = new CSDGContext()) { // Document document = new Document() { // DocumentId = Guid.NewGuid(), // DocumentName = model.DocumentName, // Description = model.Description, // CDNDocumentName = fileName, // //CDNDocumentUrl = rackspace["FileUrlRackspace"], // ExpedientId = model.ExpedientId, // PhaseId = model.SubPhaseId, // Status = "A" // }; // if (model.ContactId == null) { // Contact contact = new Contact(); // contact.ContactId = Guid.NewGuid(); // contact.ContactType = model.ContactType; // if (model.ContactType.Equals("person")) { // contact.PersonFirstName = model.PersonFirstName; // contact.PersonLastName1 = model.PersonLastName1; // contact.PersonLastName2 = model.PersonLastName2; // } // else if (model.ContactType.Equals("organization")) { // contact.OrganizationName = model.OrganizationName; // } // else if (model.ContactType.Equals("group")) { // contact.GroupName = model.GroupName; // } // contact.Status = "A"; // db.Contacts.Add(contact); // document.ContactId = contact.ContactId; // } // else { // document.ContactId = (Guid)model.ContactId; // } // db.Documents.Add(document); // Phase phase = db.Phases.Find(model.SubPhaseId); // if (phase.SendNotification) { // Expedient expedient = db.Expedients.Find(model.ExpedientId); // string server = System.Web.HttpContext.Current.Request.Url.GetLeftPart(UriPartial.Authority); // string virtualDirectory = System.Web.HttpContext.Current.Request.ApplicationPath; // string link = server + virtualDirectory + "/Customers/Documents/" + expedient.ExpedientId; // string message = "El usuario " + User.Identity.Name + " ha cargado el documento " + "<a href='#' data-id='" + document.DocumentId + "' id='getDocument'>" + document.DocumentName + "</a>" + " del contrato " + "<a href='" + link + "'>" + expedient.ContractNumber + "</a>" + " del cliente " + expedient.Customer.DisplayName; // DataTable dt = DatabaseManager.ExecuteDataTable(System.Data.CommandType.Text, "SELECT u.* FROM AspNetUsers AS u INNER JOIN AspNetUserRoles as ur ON ur.UserId = u.Id INNER JOIN AspNetRoles as r ON r.Id = ur.RoleId WHERE r.Name = 'Administrador'"); // ApplicationUser userSystem = UserManager.Users.Where(u => u.UserName.Equals("Sistema")).Single(); // foreach (DataRow user in dt.Rows) { // Notification notification = new Notification(); // notification.NotificationId = Guid.NewGuid(); // notification.NotificationType = "System"; // notification.EntitySourceType = "Document"; // notification.EntitySourceId = document.DocumentId; // notification.From = Guid.Parse(userSystem.Id); // notification.To = Guid.Parse(user["Id"].ToString()); // notification.Subject = "Se agregó el documento " + "<a href='#' data-id='" + document.DocumentId + "' id='getDocument'>" + document.DocumentName + "</a>" + " a la etapa " + phase.PhaseName + " del contrato " + "<a href='" + link + "'>" + expedient.ContractNumber + "</a>" + " del cliente " + expedient.Customer.DisplayName; // notification.Body = message; // notification.Seen = false; // notification.Status = "E"; // db.Notifications.Add(notification); // } // } // db.SaveChanges(); // return RedirectToAction("Documents", new { id = model.ExpedientId, phaseId = model.PhaseId, subPhaseId = model.SubPhaseId }); // } // } // catch (Exception ex) { // ModelState.AddModelError("", ex.Message); // } //} //return View(model); } return RedirectToAction("Index", "Home"); //return View(model); }
public string GetTempUrl(CloudStorageMananger manager) { //throw new NotImplementedException(); return this.CloudStorageItem.GetTempUrl(manager); }
public string GetTempDownloadUrl(CloudStorageMananger manager) { return this.CloudStorageItem.GetTempDownloadUrl(manager); }
public ActionResult Detail(string id) { var user = UserManager.FindById(this.GetUserId()); var cid = Guid.Parse(id); var item = user.DriveItems.SingleOrDefault(c => c.PublicKey == cid); var manager = new CloudStorageMananger(this.DBContext); if (item.ContentType.StartsWith("image/")) { } var model = new HomeDetailViewModel(manager) { DriveItem = item, IsImage = item.ContentType.StartsWith("image/") }; return View(model); }