public ActionResult Create(NoticeBoard model) { try { model.CreatorId = User.Identity.GetUserId(); var notice = _noticeBoardManager.PostNotices(model); if (Request.Files.Count > 0) { var file = Request.Files[0]; if (file != null && file.ContentLength > 0) { var fileName = Guid.NewGuid() + "_" + Path.GetFileName(file.FileName); var path = Path.Combine(Server.MapPath("~/Content/images/"), fileName); file.SaveAs(path); var image = new SiteImage { ImagePath = "/Content/images/" + fileName, Type = "Notice", TypeId = notice.Id, UploadDate = DateTime.Now, UploaderId = notice.CreatorId }; _noticeBoardManager.SaveImage(image); } else { var image = new SiteImage { ImagePath = "/Content/images/Event/defaultNotice.png", Type = "Notice", TypeId = notice.Id, UploadDate = DateTime.Now, UploaderId = notice.CreatorId }; _noticeBoardManager.SaveImage(image); } } } catch (Exception ex) { logger.Error($"Error creating notice. {ex}"); Email_Service_Model email = new Email_Service_Model(); email.ToEmail = System.Configuration.ConfigurationManager.AppSettings["BccEmail"]; email.EmailSubject = $"Failed to create notice. User- {model.Creator.UserName}"; email.EMailBody = $"Description: {model.Description}. Title: {model.Title}. Exception: {ex.ToString()}"; var emailmanager = new UtilityManager(); emailmanager.SendEmail(email); } return(RedirectToAction("Index")); }