public ActionResult Details(int id) { ContentViewModel model; try { long totalCount; model = _mapper.Map <ContentViewModel>(_contentService.GetById(id)); var attachments = _mapper.Map <List <ContentAttachmentViewModel> >(_contentAttachmentService.GetPaging(new ContentAttachment() { ContentId = id }, out totalCount, "Id", "Asc", 0, 100)); var parts = attachments.OrderBy(x => x.PartNo).ThenBy(x => x.QualityId).GroupBy(x => x.PartNo); var partsList = new List <ContentAttachmentViewModel>(); foreach (var part in parts) { var guid = Guid.NewGuid().ToString(); ContentAttachmentViewModel partModel = null; foreach (var quality in part) { if (partModel != null) { break; } quality.UniqueId = guid; partModel = quality; } partsList.Add(partModel); } ViewBag.CategoryTree = _mapper.Map <List <TreeModel> >(_contentCategoryService.Find(new ContentCategory())); ViewBag.partsList = partsList; } 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()); } return(View(model)); }
public void DbRenamer() { var patern = "[^/.a-zA-Z0-9]"; var contents = _contentService.GetPaging(new Content(), out long totalCount, take: int.MaxValue); foreach (var content in contents) { content.UpdaterId = 1116; if (!string.IsNullOrWhiteSpace(content.Photo)) { content.Photo = content.Photo.Replace("/H+/", "/HD/"); content.Photo = Regex.Replace(content.Photo, patern, "_"); } if (!string.IsNullOrWhiteSpace(content.Thumbnail)) { content.Thumbnail = content.Thumbnail.Replace("/H+/", "/HD/"); content.Thumbnail = Regex.Replace(content.Thumbnail, patern, "_"); } _contentService.Update(content); } var contentAttachments = _contentAttachmentService.GetPaging(new ContentAttachment(), out long rowsCount, take: int.MaxValue); foreach (var attachment in contentAttachments) { attachment.UpdaterId = 1116; if (!string.IsNullOrWhiteSpace(attachment.Path)) { attachment.Path = attachment.Path.Replace("/H+/", "/HD/"); attachment.Path = Regex.Replace(attachment.Path, patern, "_"); } _contentAttachmentService.Update(attachment); } }
public ActionResult Index(int?contentId) { try { ViewBag.SearchModel = new ContentAttachmentViewModel(); long totalCount; var request = new FilteredModel <ContentAttachment>(); var offset = (request.PageIndex - 1) * request.PageSize; var result = _mapper.Map <IList <ContentAttachmentViewModel> >(_contentAttachmentService.GetPaging(new ContentAttachment() { ContentId = contentId.Value }, out totalCount, request.OrderBy, request.Order, offset, request.PageSize)); ViewBag.OnePageOfEntries = new StaticPagedList <ContentAttachmentViewModel>(result, request.PageIndex, request.PageSize, (int)totalCount); HttpContext.Cache["ContentId"] = contentId; return(View()); } 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()); } }