protected void btnSave_Click(object sender, EventArgs e) { var news = new NewsBE(); BindControlToEntity(news); if (string.IsNullOrEmpty(news.Contents)) return; var newBo = new NewsBO(); news.Id = Id; int res = Id == 0 ? newBo.AddNews(news) : newBo.UpdateNews(news); string confirmMsg = string.Format( "<script>confirmDialog('{0} bản tin thành công, bạn trở về trang quản lý bản tin?');</script>", Id == 0 ? "Tạo mới" : "Cập nhật"); string alertMsg = string.Format("<script>alert('{0} bản tin không thành công');</script>", Id == 0 ? "Tạo mới" : "Cập nhật"); ltScript.Text = string.Format("{0}", res > 0 ? confirmMsg : alertMsg); }
private NewsViewModel GetDetails(Entities.News news) { var details = news.Map <NewsViewModel>(); details.Media = MediaHelper.GetMediaUrls(news.MediaIds); details.CanEdit = _newsService.CanEdit(news); details.Links = _feedLinkService.GetLinks(news.Id); details.IsReadOnly = false; details.HeaderInfo = news.Map <IntranetActivityDetailsHeaderViewModel>(); details.HeaderInfo.Dates = news.PublishDate.ToDateTimeFormat().ToEnumerable(); details.HeaderInfo.Owner = _memberService.Get(news).ToViewModel(); details.Tags = _userTagService.Get(news.Id); details.AvailableTags = _userTagProvider.GetAll(); details.LightboxPreviewModel = _lightboxHelper.GetGalleryPreviewModel(news.MediaIds, PresetStrategies.ForActivityDetails); return(details); }
private void BindControlToEntity(NewsBE news) { news.Type = int.Parse(hdfNewKind.Value); news.Title = tbTitle.Text.Trim(); news.Contents = radContent.Content; if (news.Type != 0) { return; } news.SubContent = tbSubcontent.Text.Trim(); news.ImageUrl = Filename; HttpPostedFile postedFile = uploadFile.PostedFile; if (postedFile == null || postedFile.ContentLength <= 0) return; if (string.IsNullOrEmpty(Filename) || (!string.IsNullOrEmpty(Filename) && !Filename.Equals(postedFile.FileName))) { string fileName = string.Format("{0}-{1}", DateTime.Now.ToString("yyyyMMddHHmmss"), postedFile.FileName.Replace(' ', '-').Replace('_', '-')); postedFile.SaveAs(Server.MapPath(string.Format("{0}{1}", Path, fileName))); news.ImageUrl = fileName; } }
public ActionResult Create(Entities.News news) { db.News.Add(news); db.SaveChanges(); return(RedirectToRoute("Default")); }
public void Update(Entities.News entity) { _newsDal.Update(entity); }
public void Add(Entities.News entity) { _newsDal.Add(entity); }
public NewsBuilder() { var author = new Author("*****@*****.**", "Gilmar Alcantara"); _instance = new News("Breaking News", "Any thing intresting", author); }