public async Task <IActionResult> AddNews(CreateNewsViewModel model) { if (ModelState.IsValid) { string ImageUrl = ""; if (model.Image != null) { DropBoxManager dropBoxManager = new DropBoxManager(_configuration["DropBoxAccessToken"]); ImageUrl = await dropBoxManager.Upload($"{model.CompanyName}/news", model.Image.FileName, model.Image); } News news = new News { Text = model.Text, CompanyId = model.CompanyId, Heading = model.Heading, Image = ImageUrl, Date = DateTime.Now }; _applicationContext.News.Add(news); await _applicationContext.SaveChangesAsync(); return(RedirectToAction("Index", "Company", new { id = model.CompanyName })); } return(View(model)); }
public async Task <IActionResult> CreateCompany(string id, CreateCompanyViewModel model) { if (ModelState.IsValid) { DropBoxManager dropBoxManager = new DropBoxManager(_configuration["DropBoxAccessToken"]); string FotoUrl = await dropBoxManager.Upload(model.Name, model.Foto.FileName, model.Foto); Company user = new Company { UserId = _userManager.Users.FirstOrDefault(u => u.UserName.Equals(id)).Id, Name = model.Name, Description = model.Description, Foto = FotoUrl, Deadline = model.Deadline, TargetAmount = model.TargetAmount, Category = model.Category }; _applicationContext.Add(user); await _applicationContext.SaveChangesAsync(); return(RedirectToAction("Companies", "Account", new { id })); } return(View(model)); }
public IHttpActionResult Post() { var httpRequest = HttpContext.Current.Request; var file = httpRequest.Files[0]; var fileExtension = file.FileName.Split('.').Last(); var uniqueName = this.CurrentUserId + Guid.NewGuid() + "." + fileExtension; byte[] buffer = null; using (var fs = file.InputStream) { buffer = new byte[fs.Length]; fs.Read(buffer, 0, (int)fs.Length); } var task = Task.Run(() => DropBoxManager.Upload(uniqueName, buffer)); task.Wait(); var link = "http://viber.azurewebsites.net/api/File?fileName=" + uniqueName; var receiverId = this.CurrentUser.CurrentChatId; var receiver = this.Data.Users.All() .FirstOrDefault(u => u.Id == receiverId); var message = new PrivateMessage() { Text = link, ReceiverId = receiverId, SenderId = this.CurrentUserId, IsFileLink = true }; var currentUsers = ConnectionManager.Users.Keys; if (currentUsers.Contains(receiver.UserName) && receiver.CurrentChatId == this.CurrentUser.Id) { message.Status = MessageStatus.Seen; } else if (currentUsers.Contains(receiver.UserName)) { message.Status = MessageStatus.Sent; } else { message.Status = MessageStatus.NotDelivered; } this.Data.Messages.Add(message); this.Data.SaveChanges(); var messageView = new { message.Id, message.Text, Sender = this.CurrentUserUserName, Receiver = receiver.UserName, Status = message.Status.ToString(), SenderId = this.CurrentUserId, ReceiverId = receiver.Id, MessageId = message.Id, IsFileLink = true }; this.HubContex.Clients.User(receiver.UserName).pushMessageToClient(messageView); this.HubContex.Clients.User(this.CurrentUserUserName).pushSelfMessage(messageView); return(this.Ok()); }