Exemplo n.º 1
0
        public ActionResult Create(AttachmentInfo model,FormCollection fc) {
            bool errors = false;
            if(string.IsNullOrEmpty(model.Title)){
                errors = true;
                ModelState.AddModelError("Title", "Please enter the name of the attachment");
            }
            if(!errors && ModelState.IsValid){

                //分类
                model.CategoryId = Utils.StrToInt(fc["ddlCats"], 0);
                if (model.CategoryId == 0)
                {
                    ModelState.AddModelError("CategoryError", "Please select the category");
                }
                else
                {

                    int id = AttachmentService.Create(model).Id;
                    ViewBag.Status = false;
                    if (id > 0)
                    {
                        ViewBag.Status = true;
                    }
                }
            }

            return View(model);
        }
Exemplo n.º 2
0
 /// <summary>
 /// 添加或编辑
 /// </summary>
 /// <param name="model"></param>
 /// <returns></returns>
 public static AttachmentInfo Create(AttachmentInfo model) {
     if (model.Id == 0)
     {
         int id = AttachmentManage.Insert(model);
         model.Id = id;
     }
     else {
         AttachmentManage.Update(model);
     }
     return model;
 }
Exemplo n.º 3
0
        /// <summary>
        /// 更新
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public static int Update(AttachmentInfo model) {
            string strSQL = "UPDATE dbo.Attachment SET Title = @Title,ImageUrl = @ImageUrl,DownloadUrl = @DownloadUrl,Size = @Size ,Sort = @Sort,CategoryId = @CategoryId WHERE Id = @Id";
            SqlParameter[] param = { 
                                    new SqlParameter("Id",SqlDbType.Int),
                                    new SqlParameter("Title",SqlDbType.NVarChar),
                                    new SqlParameter("ImageUrl",SqlDbType.NVarChar),
                                    new SqlParameter("DownloadUrl",SqlDbType.NVarChar),
                                    new SqlParameter("Size",SqlDbType.Int),
                                    new SqlParameter("Sort",SqlDbType.Int),
                                    new SqlParameter("CategoryId",SqlDbType.Int),
                                   };
            param[0].Value = model.Id;
            param[1].Value = model.Title ?? string.Empty;
            param[2].Value = model.ImageUrl ?? string.Empty;
            param[3].Value = model.DownloadUrl ?? string.Empty;
            param[4].Value = model.Size;
            param[5].Value = model.Sort;
            param[6].Value = model.CategoryId;

            return Goodspeed.Library.Data.SQLPlus.ExecuteNonQuery(CommandType.Text,strSQL,param);
        }
Exemplo n.º 4
0
        /// <summary>
        /// 插入
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public static int Insert(AttachmentInfo model) {
            string strSQL = "INSERT INTO dbo.Attachment(Title,ImageUrl,DownloadUrl,IsDeleted,CreateDateTime,Size,Sort,CategoryId) VALUES(@Title,@ImageUrl,@DownloadUrl,0,GETDATE(),@Size,@Sort,@CategoryId);SELECT @@IDENTITY;";
            SqlParameter[] param = { 
                                    new SqlParameter("Id",SqlDbType.Int),
                                    new SqlParameter("Title",SqlDbType.NVarChar),
                                    new SqlParameter("ImageUrl",SqlDbType.NVarChar),
                                    new SqlParameter("DownloadUrl",SqlDbType.NVarChar),
                                    new SqlParameter("Size",SqlDbType.Int),
                                    new SqlParameter("Sort",SqlDbType.Int),
                                    new SqlParameter("CategoryId",SqlDbType.Int),
                                   };
            param[0].Value = model.Id;
            param[1].Value = model.Title ?? string.Empty;
            param[2].Value = model.ImageUrl ?? string.Empty;
            param[3].Value = model.DownloadUrl ?? string.Empty;
            param[4].Value = model.Size;
            param[5].Value = model.Sort;
            param[6].Value = model.CategoryId;

            return Convert.ToInt32(Goodspeed.Library.Data.SQLPlus.ExecuteScalar(CommandType.Text,strSQL,param));
        }