コード例 #1
0
 public ActionResult CreateGallery(GalleryDto model)
 {
     if (model != null)
     {
         var dto = model;
         dto.CreatedBy = "Authorized User";
         dto.CreatedOn = DateTime.Now;
        var galleryId = GalleryQueries.CreateGallery(dto);
        return RedirectToAction("Edit", new { id = galleryId });
     }
     return View("Create");
 }
コード例 #2
0
        public static int CreateGallery(GalleryDto gallery)
        {
            var id = 0;
            using (var conn = Connection.GetConnection())
            {
                conn.Open();
                var createCommand = "INSERT INTO Galleries (Title,Description,CreatedOn,CreatedBy) VALUES ('"
                                    + gallery.Title.ToDbCleanString()  + "', '"
                                    + gallery.Description.ToDbCleanString() + "', '"
                                    + DateTime.Now.ToString("M/d/yyyy hh:mm:ss tt") + "', '"
                                    + gallery.CreatedBy + "'); SELECT SCOPE_IDENTITY()";

                using (var cmd = new SqlCommand(createCommand, conn))
                {
                    cmd.CommandType = CommandType.Text;
                    id = Convert.ToInt32(cmd.ExecuteScalar());
                }
                conn.Close();
            }
            return id;
        }
コード例 #3
0
 public GalleryModel()
 {
     Gallery = new GalleryDto();
     Images = new List<ImagesDto>();
 }
コード例 #4
0
 private static GalleryDto ReadGallery(SqlDataReader dr)
 {
     var g = new GalleryDto
     {
         GalleryId = Convert.ToInt32(dr["Id"]),
         Title = dr["Title"] != DBNull.Value ? dr["Title"].ToString() : string.Empty,
         Description = dr["Description"] != DBNull.Value ? dr["Description"].ToString() : string.Empty,
         CreatedBy = dr["CreatedBy"] != DBNull.Value ? dr["CreatedBy"].ToString() : string.Empty,
         CreatedOn = dr["CreatedOn"] != DBNull.Value ? Convert.ToDateTime(dr["CreatedOn"].ToString()) : DateTime.MinValue,
         CoverImage = new ImagesDto()
                          {
                              GalleryId = Convert.ToInt32(dr["Id"]),
                              ImageId = dr["ImageId"] != DBNull.Value ? Convert.ToInt32(dr["ImageId"]) : 0,
                              Title = dr["ImageTitle"] != DBNull.Value ? dr["ImageTitle"].ToString() : string.Empty,
                              Description = dr["ImageDescription"] != DBNull.Value ? dr["ImageDescription"].ToString() : string.Empty,
                              //Url = dr["ImageUrl"] != DBNull.Value ? dr["ImageUrl"].ToString() : string.Empty
                          }
     };
     return g;
 }
コード例 #5
0
 public static GalleryDto GetGalleryById(int galleryId)
 {
     var gallery = new GalleryDto();
     using (var conn = Connection.GetConnection())
     {
         conn.Open();
         using (var cmd = new SqlCommand("SELECT g.*, i.Id as ImageId, i.Title as ImageTitle, i.Description as ImageDescription, i.Url as ImageUrl" +
                                         " FROM Galleries g LEFT JOIN Images i on i.GalleryId = g.Id WHERE g.Id = " + galleryId, conn))
         {
             cmd.CommandType = CommandType.Text;
             var dr = cmd.ExecuteReader();
             while (dr.Read())
             {
                 gallery = ReadGallery(dr);
             }
         }
         conn.Close();
     }
     return gallery;
 }