/// <summary> /// 修改分组名称 /// </summary> /// <returns></returns> public ApiResult modifyGroupName() { try { PhotoGroupModel model = PhotoGroupBLL.Instance.GetModel(this.groupId); if (model != null) { model.PhotoName = this.groupName; if (PhotoGroupBLL.Instance.Update(model)) { return(new ApiResult(HQEnums.ResultOptionType.OK)); } else { return(new ApiResult(HQEnums.ResultOptionType.失败, "修改名称失败,请稍后再试...")); } } else { return(new ApiResult(HQEnums.ResultOptionType.没有信息, "没有该分组信息")); } } catch (Exception ex) { LogHelper.WriteError(string.Format("modifyGroupName error-->Statck:{0},Message:{1}", ex.StackTrace, ex.Message)); return(new ApiResult(HQEnums.ResultOptionType.务器错误, "服务器错误")); } }
/// <summary> /// 删除分组并且把分组下面的图片移动到未分组状态(groupId=0) /// </summary> /// <returns></returns> public ApiResult deleteGroup() { try { PhotoGroupModel model = PhotoGroupBLL.Instance.GetModel(this.groupId); if (model != null) { if (PhotoGroupBLL.Instance.DeleteList(this.groupId.ToString())) { GalleryBLL.Instance.UpdateCalleryGroupId(this.groupId); return(new ApiResult(HQEnums.ResultOptionType.OK)); } else { return(new ApiResult(HQEnums.ResultOptionType.失败, "删除分组失败")); } } else { return(new ApiResult(HQEnums.ResultOptionType.没有信息, "没有该分组信息")); } } catch (Exception ex) { LogHelper.WriteError(string.Format("deleteGroup error-->Statck:{0},Message:{1}", ex.StackTrace, ex.Message)); return(new ApiResult(HQEnums.ResultOptionType.务器错误, "服务器错误")); } }
public void UpdateIdDoesntExistThrowsTest() { var manager = GetManager(); var model = new PhotoGroupModel(); _photoGroupRepositoryMock.Setup(x => x.Exists(It.IsAny <int>())).Returns(false); Assert.Throws <BusinessException>(() => manager.Update(model)); }
public void Update(PhotoGroupModel model) { Guard.NotNull(model, nameof(model), Constants.NullExceptionGenerator); _logger.LogInformation($"updating photo group: {JsonConvert.SerializeObject(model)}"); var entity = Mapper.Map <PhotoGroup>(model); ValidatePhotoGroupIdExists(model.Id); _photoGroupRepository.Update(entity); }
public void UpdateModelPassedToRepositoryTest() { var manager = GetManager(); var model = new PhotoGroupModel(); _photoGroupRepositoryMock.Setup(x => x.Exists(It.IsAny <int>())).Returns(true); manager.Update(model); _photoGroupRepositoryMock.Verify( x => x.Update(It.Is <PhotoGroup>(y => y != null)), Times.Once); }
public void PhotoGroupModelMapTest() { var model = new PhotoGroupModel { Id = 1, Name = Guid.NewGuid().ToString(), SortOrder = 1 }; var entity = Mapper.Map <PhotoGroup>(model); Assert.Equal(model.Id, entity.Id); Assert.Equal(model.Name, entity.Name); Assert.Equal(model.SortOrder, entity.SortOrder); }
/// <summary> /// 更新一条数据 /// </summary> public bool Update(PhotoGroupModel model) { StringBuilder strSql = new StringBuilder(); strSql.Append("update HQ_PhotoGroup set "); strSql.Append("PhotoName=@PhotoName,"); strSql.Append("FatherID=@FatherID,"); strSql.Append("Photo_Customer_ID=@Photo_Customer_ID,"); strSql.Append("Photo_Cover=@Photo_Cover,"); strSql.Append("Photo_Time=@Photo_Time,"); strSql.Append("FilePath=@FilePath "); strSql.Append(" where PhotoID=@PhotoID"); SqlParameter[] parameters = { new SqlParameter("@PhotoName", SqlDbType.VarChar, 100), new SqlParameter("@FatherID", SqlDbType.Int, 4), new SqlParameter("@Photo_Customer_ID", SqlDbType.Int, 4), new SqlParameter("@Photo_Cover", SqlDbType.VarChar, 500), new SqlParameter("@Photo_Time", SqlDbType.DateTime), new SqlParameter("@PhotoID", SqlDbType.Int, 4), new SqlParameter("@FilePath", SqlDbType.VarChar) }; parameters[0].Value = model.PhotoName; parameters[1].Value = model.FatherID; parameters[2].Value = model.Photo_Customer_ID; parameters[3].Value = model.Photo_Cover; parameters[4].Value = model.Photo_Time; parameters[5].Value = model.PhotoID; parameters[6].Value = model.FilePath; int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters); if (rows > 0) { return(true); } else { return(false); } }
public ActionResult deleteGroup(int groupId, string callback) { string resultJson = ""; string json = ""; try { PhotoGroupModel model = PhotoGroupBLL.Instance.GetModel(groupId); if (model != null) { if (PhotoGroupBLL.Instance.DeleteList(groupId.ToString())) { GalleryBLL.Instance.UpdateCalleryGroupId(groupId); json = JsonConvert.SerializeObject(new ApiResult(HQEnums.ResultOptionType.OK)); } else { json = JsonConvert.SerializeObject(new ApiResult(HQEnums.ResultOptionType.失败, "删除分组失败")); } } else { json = JsonConvert.SerializeObject(new ApiResult(HQEnums.ResultOptionType.没有信息, "没有该分组信息")); } } catch (Exception ex) { LogHelper.WriteError(string.Format("deleteGroup error-->Statck:{0},Message:{1}", ex.StackTrace, ex.Message)); json = JsonConvert.SerializeObject(new ApiResult(HQEnums.ResultOptionType.务器错误)); } if (!string.IsNullOrEmpty(callback)) { resultJson = callback + "(" + json + ")"; } else { resultJson = json; } return(Content(resultJson, "application/json")); }
public ActionResult modifyGroupName(int groupId, string groupName, string callback) { string resultJson = ""; string json = ""; try { PhotoGroupModel model = PhotoGroupBLL.Instance.GetModel(groupId); if (model != null) { model.PhotoName = groupName; if (PhotoGroupBLL.Instance.Update(model)) { json = JsonConvert.SerializeObject(new ApiResult(HQEnums.ResultOptionType.OK)); } else { json = JsonConvert.SerializeObject(new ApiResult(HQEnums.ResultOptionType.失败, "修改名称失败,请稍后再试...")); } } else { json = JsonConvert.SerializeObject(new ApiResult(HQEnums.ResultOptionType.没有信息, "没有该分组信息")); } } catch (Exception ex) { LogHelper.WriteError(string.Format("modifyGroupName error-->Statck:{0},Message:{1}", ex.StackTrace, ex.Message)); json = JsonConvert.SerializeObject(new ApiResult(HQEnums.ResultOptionType.务器错误)); } if (!string.IsNullOrEmpty(callback)) { resultJson = callback + "(" + json + ")"; } else { resultJson = json; } return(Content(resultJson, "application/json")); }
/// <summary> /// 得到一个对象实体 /// </summary> public PhotoGroupModel DataRowToModel(DataRow row) { PhotoGroupModel model = new PhotoGroupModel(); if (row != null) { if (row["PhotoID"] != null && row["PhotoID"].ToString() != "") { model.PhotoID = int.Parse(row["PhotoID"].ToString()); } if (row["PhotoName"] != null) { model.PhotoName = row["PhotoName"].ToString(); } if (row["FatherID"] != null && row["FatherID"].ToString() != "") { model.FatherID = int.Parse(row["FatherID"].ToString()); } if (row["Photo_Customer_ID"] != null && row["Photo_Customer_ID"].ToString() != "") { model.Photo_Customer_ID = int.Parse(row["Photo_Customer_ID"].ToString()); } if (row["Photo_Cover"] != null) { model.Photo_Cover = row["Photo_Cover"].ToString(); } if (row["Photo_Time"] != null && row["Photo_Time"].ToString() != "") { model.Photo_Time = DateTime.Parse(row["Photo_Time"].ToString()); } if (row["FilePath"] != null && row["FilePath"].ToString() != "") { model.FilePath = row["FilePath"].ToString(); } } return(model); }
/// <summary> /// 增加一条数据 /// </summary> public int Add(PhotoGroupModel model) { StringBuilder strSql = new StringBuilder(); strSql.Append("insert into HQ_PhotoGroup("); strSql.Append("PhotoName,FatherID,Photo_Customer_ID,Photo_Cover,Photo_Time,FilePath)"); strSql.Append(" values ("); strSql.Append("@PhotoName,@FatherID,@Photo_Customer_ID,@Photo_Cover,@Photo_Time,@FilePath)"); strSql.Append(";select @@IDENTITY"); SqlParameter[] parameters = { new SqlParameter("@PhotoName", SqlDbType.VarChar, 100), new SqlParameter("@FatherID", SqlDbType.Int, 4), new SqlParameter("@Photo_Customer_ID", SqlDbType.Int, 4), new SqlParameter("@Photo_Cover", SqlDbType.VarChar, 500), new SqlParameter("@Photo_Time", SqlDbType.DateTime), new SqlParameter("@FilePath", SqlDbType.VarChar) }; parameters[0].Value = model.PhotoName; parameters[1].Value = model.FatherID; parameters[2].Value = model.Photo_Customer_ID; parameters[3].Value = model.Photo_Cover; parameters[4].Value = model.Photo_Time; parameters[5].Value = model.FilePath; object obj = DbHelperSQL.GetSingle(strSql.ToString(), parameters); if (obj == null) { return(0); } else { return(Convert.ToInt32(obj)); } }
/// <summary> /// 得到一个对象实体 /// </summary> public PhotoGroupModel GetModel(int PhotoID) { StringBuilder strSql = new StringBuilder(); strSql.Append("select top 1 PhotoID,PhotoName,FatherID,Photo_Customer_ID,Photo_Cover,Photo_Time,FilePath from HQ_PhotoGroup "); strSql.Append(" where PhotoID=@PhotoID"); SqlParameter[] parameters = { new SqlParameter("@PhotoID", SqlDbType.Int, 4) }; parameters[0].Value = PhotoID; PhotoGroupModel model = new PhotoGroupModel(); DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters); if (ds.Tables[0].Rows.Count > 0) { return(DataRowToModel(ds.Tables[0].Rows[0])); } else { return(null); } }
/// <summary> /// 更新一条数据 /// </summary> public bool Update(PhotoGroupModel model) { return(dal.Update(model)); }
/// <summary> /// 增加一条数据 /// </summary> public int Add(PhotoGroupModel model) { return(dal.Add(model)); }
public ActionResult Update([FromBody] PhotoGroupModel model) { _photoGroupManager.Update(model); return(Ok()); }