public void AddAndModify_ReturnNull_Withwid() { var service = new PhotoService(); var dto = new photoActionDTO() { wid = 36, beginDate = "2015-09-01", endDate = DateTime.Now.AddDays(5).ToString(), actContent = "test20151", brief = "jianjie", isAllowSharing = true }; service.Add(dto); Assert.IsTrue(dto.id > 0); photoActionDTO model = service.GetModel(dto.id); Assert.AreEqual(dto.wid, model.wid); dto.brief = "test间接"; service.Modify(dto); Assert.IsNotNull(dto); model = service.GetModel(dto.id); Assert.AreEqual(dto.brief, model.brief); }
public Photo Post() { Photo photo = new Photo { Title = Request.Form["title"], Caption = Request.Form["caption"] }; IFormFile file = Request.Form.Files["file"]; return(photoService.Add(photo, file)); }
/// <summary> /// 添加用户 /// </summary> /// <param name="context"></param> public void AddProductRequest(HttpContext context) { var response = new ResponseMessage(); try { string title = context.Request.Form["Title"]; string cateId = context.Request.Form["CateId"]; string content = context.Request.Form["Content"]; var marketPrice = Convert.ToDecimal(context.Request.Form["MarketPrice"]); var price = Convert.ToDecimal(context.Request.Form["Price"]); var stock = Convert.ToInt32(context.Request.Form["Stock"]); var postTime = Convert.ToDateTime(context.Request.Form["PostTime"]); var path = context.Request.Form["PhotoId"]; var Id = Guid.NewGuid().ToString(); /*如何开启事务 ?*/ //图片 Photo photo = new Photo { PhotoId = Guid.NewGuid().ToString(), PhotoUrl = path, ProductId = Id }; _photoInfoService.Add(photo); //商品 Product Product = new Product() { ProductId = Id, Title = title, CateId = cateId, Content = content, MarketPrice = marketPrice, Stock = stock, PostTime = postTime, Price = price, Icon = path }; var add = _InfoService.Add(Product); response.code = add == true ? 0 : 500; response.msg = "添加成功"; context.Response.Write(SerializeHelp.ToJson(response)); } catch (Exception e) { string eroor = e.Message; response.code = 500; response.msg = "添加失败"; context.Response.Write(SerializeHelp.ToJson(response)); } }
public IActionResult AddPhoto(PhotoModel model) { if (!ModelState.IsValid) { return(View(model)); } photoService.Add(new Photo { AlbumId = model.AlbumId, Description = model.Description, Image = model.Photo.GetFileBytes() }); return(RedirectToAction("EditAlbum", "Album", new { id = model.AlbumId })); }
public ActionResult Add(PhotoVM _Photo, HttpPostedFileBase image) { _Photo.Photo.UserID = _UserService.GetByDefault(x => x.UserName == User.Identity.Name).ID; if (image == null) { return(View()); } else { _Photo.Photo.Url = new byte[image.ContentLength]; image.InputStream.Read(_Photo.Photo.Url, 0, image.ContentLength); _Photo.Photo.Name = image.FileName; _Photo.Photo.PhotoCategoryID = _PhotoCategoryService.GetByDefault(x => x.Name == _Photo.CategoryName).ID; _PhotoService.Add(_Photo.Photo); } return(Redirect("/SysAdmin/Photo/List")); }
private void Button_Click(object sender, RoutedEventArgs e) { OpenFileDialog dlg = new OpenFileDialog(); dlg.ShowDialog(); string imageName = Guid.NewGuid().ToString() + ".jpg"; //08f71055-72b0-4075-bbc9-8472782e3b7f.jpg System.Drawing.Image img = System.Drawing.Image.FromFile(dlg.FileName); img = CompressImage.CreateImage((Bitmap)img, 500, 500); img.Save(Environment.CurrentDirectory + "//" + imageName, ImageFormat.Jpeg); Data.Models.User_Photo user_Photo = new User_Photo(); { user_Photo.Name = imageName; user_Photo.User_Id = StartWindow.selectID; } PhotoService photoService = new PhotoService(); photoService.Add(user_Photo); }
public ActionResult HomePage(Tweet tweet, Hashtag hashtag, HttpPostedFileBase[] PhotoVideo, Photo photo, Video video)//Tweet ve Hashtag Ekleme { AppUser gelen = (AppUser)Session["oturum"]; if (Session["oturum"] != null) { gelen = (AppUser)Session["oturum"]; tweet.AppUserID = gelen.ID; } if (ModelState.IsValid) { tweet.Like = 0; tweet.Dislike = 0; tweet.Retweet = 0; #region Add Hashtag if (tweet.TweetText != null) { if (tweet.TweetText.Contains('#')) { string[] text = tweet.TweetText.Split(' '); foreach (var item in text) { if (hs.Any(x => x.HashTag.Contains(item))) { var hashtagItem = hs.GetByDefault(x => x.HashTag == item); hashtagItem.Quantity += 1; hashtagItem.Tweets.Add(tweet); hs.Update(hashtagItem); } else { if (item.Contains('#')) { hashtag.HashTag = item; hashtag.Quantity = 1; tweet.Hashtags.Add(hashtag); ts.Add(tweet); } } } } else { ts.Add(tweet); } } else { ViewBag.Message = "Tweet Giriniz."; return(View()); } #endregion #region Add Photo and Video bool isUploadedVideo; bool isUploadedPhoto; foreach (var itemPhoto in PhotoVideo) { if (itemPhoto != null) { if (itemPhoto.ContentType.Contains("image")) { string photoFileResult = FxFunction.Upload(PhotoVideo, FolderPath.TweetPhoto, out isUploadedPhoto); if (isUploadedPhoto) { photo.TweetID = tweet.ID; photo.Description = tweet.TweetText; photo.ImagePath = photoFileResult; ps.Add(photo); } } else if (itemPhoto.ContentType.Contains("video")) { string videoFileResult = FxFunction.Upload(PhotoVideo, FolderPath.TweetMovie, out isUploadedVideo); if (isUploadedVideo) { video.ID = Guid.NewGuid(); video.Description = tweet.TweetText; video.VideoPath = videoFileResult; vs.Add(video); tweet.TweetVideoID = video.ID; ts.Update(tweet); } } } } return(RedirectToAction("HomePage")); #endregion } else { ViewBag.Message = "Ekleme sırasında hata oluştu."; } ViewBag.AppUserID = new SelectList(aus.GetActive(), "ID", "Name", tweet.AppUserID); return(View()); }
//保存 protected void btnSubmit_Click(object sender, EventArgs e) { Model.wx_userweixin weixin = GetWeiXinCode(); Model.wx_requestRuleContent rc = new Model.wx_requestRuleContent(); int id = MyCommFun.Str2Int(hidid.Value); #region //先判断 string strErr = ""; if (this.txtKW.Text.Trim().Length == 0) { strErr += "关键词不能为空!"; } if (this.txtactName.Text.Trim().Length == 0) { strErr += "活动名称不能为空!"; } if (this.txtbeginDate.Text.Trim().Length == 0 || !MyCommFun.isDateTime(txtbeginDate.Text)) { strErr += "开始时间不能为空!"; } if (this.txtendDate.Text.Trim().Length == 0 || !MyCommFun.isDateTime(txtendDate.Text)) { strErr += "结束时间不能为空!"; } if (strErr != "") { JscriptMsg(strErr, "back", "Error"); return; } DateTime begin = MyCommFun.Obj2DateTime(txtbeginDate.Text.Trim()); DateTime end = MyCommFun.Obj2DateTime(txtendDate.Text.Trim()); if (begin >= end) { JscriptMsg("开始时间必须小于结束时间", "back", "Error"); return; } #endregion #region 赋值 var dto = new photoActionDTO(); Model.wx_requestRule rule = new Model.wx_requestRule(); if (id > 0) { dto = _service.GetModel(id); } dto.actName = txtactName.Text.Trim(); dto.brief = txtbrief.Value.Trim(); dto.beginDate = begin.ToString(); dto.endDate = end.ToString(); dto.actContent = txtactContent.Value.Trim(); #endregion if (id <= 0) { //新增 dto.wid = weixin.id; //1新增主表 _service.Add(dto); id = dto.id; //3 新增回复规则表 AddRule(weixin.id, id); AddAdminLog(MXEnums.ActionEnum.Add.ToString(), "添加湖怪活动,主键为" + id); //记录日志//1e2124dd04e11d01b9df2865f85944be JscriptMsg("添加湖怪活动成功!", "photolist.aspx", "Success"); } else { //修改 //1修改主表 _service.Modify(dto); //3 修改回复规则表 IList <Model.wx_requestRule> rlist = rBll.GetModelList("modelFunctionName = '湖怪' and modelFunctionId=" + id); if (rlist != null && rlist.Count > 0) { rule = rlist[0]; rule.reqKeywords = txtKW.Text.Trim(); rBll.Update(rule); } else { AddRule(weixin.id, id); } AddAdminLog(MXEnums.ActionEnum.Edit.ToString(), "修改湖怪活动,主键为" + id); //记录日志 JscriptMsg("修改湖怪活动成功!", "photolist.aspx", "Success"); } }