public ActionResult Create(ContentAttachmentViewModel collection) { try { collection.ContentId = Convert.ToInt32(HttpContext.Cache["ContentId"]); var info = new FileInfo(Server.MapPath(collection.Path)); collection.FileSize = Convert.ToInt32(info.Length); collection.CreatedAt = ""; if (ModelState.IsValid) { collection.CreatorId = LogedInAdmin.Id; var model = _mapper.Map <ContentAttachment>(collection); model.CreatedAt = DateTime.Now; model.Size = collection.FileSize; _contentAttachmentService.Insert(model); return(RedirectToAction("Index", new { contentId = Convert.ToInt32(HttpContext.Cache["ContentId"]) })); } ModelState.AddModelError(string.Empty, GeneralMessages.DefectiveEntry); return(View(collection)); } catch (Exception ex) { _logger.Error(ex); if (ex.InnerException != null && ex.InnerException.Source.Equals(GeneralMessages.ExceptionSource)) { ModelState.AddModelError(string.Empty, ex.Message); } else { ModelState.AddModelError(string.Empty, GeneralMessages.UnexpectedError); } return(View(collection)); } }