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 Edit(int id, ContentAttachmentViewModel collection) { try { if (id > 0) { var info = new FileInfo(Server.MapPath(collection.Path)); collection.FileSize = Convert.ToInt32(info.Length); if (ModelState.IsValid) { collection.UpdaterId = LogedInAdmin.Id; var model = _mapper.Map <ContentAttachment>(collection); model.UpdatedAt = DateTime.Now; _contentAttachmentService.Update(model); return(RedirectToAction("Index", new { contentId = collection.ContentId })); } ModelState.AddModelError(string.Empty, GeneralMessages.DefectiveEntry); } else { ModelState.AddModelError(string.Empty, GeneralMessages.EmptyId); } 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)); } }