public ActionResult Create(File data) { string actionName = this.ControllerContext.RouteData.Values["action"].ToString(); string controllerName = this.ControllerContext.RouteData.Values["controller"].ToString(); try { if (ModelState.IsValid) { FilesRepository fr = new FilesRepository(); UsersRepository ur = new UsersRepository(); var FileCreater = ur.GetUserByUsername(User.Identity.Name); data.User_id = FileCreater.Username; fr.AddFiles(data); //new LogsRepository().Log(User.Identity.Name, controllerName + "\\" + actionName, "Post" + data.Id + "added", LogType.Information); ViewBag.Message = "Item added successfully"; return(RedirectToAction("Upload", new { id = data.id })); } else { ViewBag.Error = "Check your inputs"; } } catch (Exception ex) { //new LogsRepository().Log(User.Identity.Name, controllerName + "\\" + actionName, ex, LogType.Error); ViewBag.Error = "Item failed to be added"; } return(View()); }