public IActionResult CreateAnnouncemant(Announcemants model, IFormFile file) { using (FreelanceContext _context = new FreelanceContext()) { string dirpath = Path.GetFullPath("/files/"); if (!Directory.Exists(dirpath)) { Directory.CreateDirectory(dirpath); } string path = dirpath + file.FileName; using (var stream = System.IO.File.Create(path)) { file.CopyTo(stream); } model.UserId = _context.Accounts.Single(a => a.Login == User.Identity.Name).Id; _context.Announcemants.Add(new Announcemants() { FullDescription = model.FullDescription, MaxWage = model.MaxWage, MinWage = model.MinWage, Title = model.Title, UserId = model.UserId, WageTypeId = model.WageTypeId, Deadline = model.Deadline, PublicDate = DateTime.Now.Date, FilePath = path, }); _context.SaveChanges(); return(RedirectToAction("Index")); } }
public IActionResult AddMyBind(Announcemants model, string text) { using (FreelanceContext _context = new FreelanceContext()) { var userId = _context.Accounts.Single(a => a.Login == User.Identity.Name).Id; _context.Binds.Add(new Binds() { BindText = text, UserId = userId, AnnouncemantId = model.Id }); _context.SaveChanges(); return(RedirectToAction("Index", "Dashboard")); } }