Beispiel #1
0
        public HttpResponseMessage GetGallery()
        {
            try {
                var allGallery = Gallery.GetGalleryData("");
                if (allGallery == null)
                {
                    return(Request.CreateResponse(HttpStatusCode.Forbidden));
                }

                return(Request.CreateResponse(HttpStatusCode.OK, JsonConvert.SerializeObject(allGallery)));
            }catch (Exception) {
                return(Request.CreateResponse(HttpStatusCode.NotFound));
            }
        }
Beispiel #2
0
        public HttpResponseMessage GetQuestionByID(int key)
        {
            try
            {
                //QuestionID QuestionDesc    UserUpdated DateUpdated IpAddress TagList LikeCnt AnswerCnt   Viewer
                var q       = Question.GetQuestionData(Utilities.ToString(key));
                var gallery = new ImageGallery();

                Questions newQuestion = q.FirstOrDefault();

                if (IsMe.UserName != "")
                {
                    Question.MngQuestionData(dbUtilities.opUPDATE, ref newQuestion, true);
                }

                q = q.Select(r => new Questions
                {
                    QuestionID    = r.QuestionID,
                    CategoryID    = r.CategoryID,
                    QuestionTitle = r.QuestionTitle,
                    QuestionDesc  = r.QuestionDesc,
                    UserID        = r.UserID,
                    UserUpdated   = r.UserUpdated,
                    Avatar        = r.Avatar,
                    DateUpdated   = r.DateUpdated,
                    IpAddress     = r.IpAddress,
                    TagList       = r.TagList,
                    IsPublic      = r.IsPublic,
                    GalleyList    = (r.IsPublic == 0) ? gallery.GetGalleryData(Utilities.ToString(r.QuestionID), "", true) : null,
                    UserList      = r.UserList,
                    LikeCnt       = r.LikeCnt,
                    AnswerCnt     = r.AnswerCnt,
                    ViewCnt       = r.ViewCnt,
                }).ToList <Questions>();

                Msg = Request.CreateResponse(HttpStatusCode.OK, JsonConvert.SerializeObject(q));
            } catch (Exception ex) {
                Project.GetErrorMessage(ex.Message);
                Msg = Request.CreateResponse(HttpStatusCode.NotFound);
            }
            return(Msg);
        }
Beispiel #3
0
        private void CreateGallery()
        {
            var     ig       = new ImageGallery();
            var     im       = new Images();
            string  desc     = "";
            string  fileName = "";
            string  filePath = "";
            string  suffix   = "";
            dynamic trans    = null;
            dynamic conn     = null;
            int     op       = 0;

            try
            {
                conn  = Project.dal.OpenConn("");
                trans = Project.dal.BeginTrans(conn);

                var file = Request.Files;

                desc = Request.Form["txtDesc"] + "";


                var gList = ig.GetGalleryData(Request.QueryString["k"] + "");

                if (gList != null && gList.Count > 0)
                {
                    op           = dbUtilities.opUPDATE;
                    ig.GalleryID = gList[0].GalleryID;
                }
                else
                {
                    op = dbUtilities.opINSERT;
                }

                ig.QuestionID  = Utilities.ToInt(Request.QueryString["k"]);
                ig.GalleryDesc = desc;
                ig.ActiveFlag  = 1;

                ig.MngGalleryData(op, ref ig, conn, trans);


                List <HttpPostedFile> lstFile = new List <HttpPostedFile>();
                for (int i = 0; i < Request.Files.Count; i++)
                {
                    var fileUpload = Request.Files[i];
                    if ((fileUpload.ContentType.Contains("image") || fileUpload.ContentType.Contains("video")) && fileUpload.ContentLength > 0)
                    {
                        lstFile.Add(fileUpload);
                    }
                }

                filePath = Server.MapPath("~/Files/Upload/Images/");


                for (int i = 0; i < lstFile.Count; i++)
                {
                    suffix = i + "_" + DateTime.Now.ToString("yyyyMMddHHmmss");
                    HttpPostedFile FU  = lstFile[i];
                    string         ext = Path.GetExtension(FU.FileName);
                    fileName = ig.GalleryID + "_" + suffix + "_" + new Random().Next(0, 50) + ext;

                    im.GalleryID  = ig.GalleryID;
                    im.ActiveFlag = 1;
                    im.ShowFlag   = (i == lstFile.Count - 1) ? 1 : 0;
                    im.ImageUrl   = fileName;
                    ig.MngImageData(dbUtilities.opINSERT, ref im, conn, trans);

                    FU.SaveAs(filePath + fileName);
                }

                Project.dal.CommitTrans(ref trans);
            }catch (Exception ex) {
                Project.dal.RollbackTrans(ref trans);
                throw ex;
            }finally {
                trans = null;
                Project.dal.CloseConn(ref conn);
            }
        }