示例#1
0
        public ActionResult New(PM_Issues Issu)
        {
            string Message, fileName, actualFileName;

            Message = fileName = actualFileName = string.Empty;
            bool      flag   = false;
            var       issues = HttpContext.Request["Issue"];
            var       File   = HttpContext.Request["file"];
            PM_Issues Issue  = JsonConvert.DeserializeObject <PM_Issues>(issues);

            HttpFileCollectionBase files = HttpContext.Request.Files;

            if (Request.Files != null)
            {
                if (Request.Files.Count > 0)
                {
                    var file = Request.Files[0];
                    actualFileName = file.FileName;
                    fileName       = Guid.NewGuid() + Path.GetExtension(file.FileName);
                    int size = file.ContentLength;

                    try
                    {
                        string FilePath = Path.Combine(Server.MapPath("~/Content/Files/") + fileName).ToString();
                        file.SaveAs(Path.Combine(Server.MapPath("~/Content/Files/"), fileName));
                        Issue.FilePath = "/Content/Files/" + fileName.ToString(); //FilePath;
                    }
                    catch (Exception ex)
                    {
                        Message = "File upload failed! Please try again";
                    }
                }
            }



            if (Issue.IssueId != 0)
            {
                var res = bal.Manage(bal.Filter_Update, Issue);
                return(Json(res, JsonRequestBehavior.AllowGet));
            }
            else
            {
                var res = bal.Manage(bal.Filter_Insert, Issue, ViewBag.UserId);
                return(Json(res, JsonRequestBehavior.AllowGet));
            }
        }
示例#2
0
        public HttpResponseMessage InsertUpdateIssueTicket(PM_Issues Issu)
        {
            PM_IssueBL bal = new PM_IssueBL();

            string Message        = string.Empty;
            string fileName       = string.Empty;
            string actualFileName = string.Empty;

            //var issues = HttpContext.Current.Request["Issue"];
            //var File = HttpContext.Current.Request["file"];

            //// if data is simple json object then no need to deserilized
            //PM_Issues Issue = JsonConvert.DeserializeObject<PM_Issues>(issues);

            //// HttpFileCollectionBase files = HttpContext.Request.Files;

            ////upload the file to server
            //if (HttpContext.Current.Request.Files != null)
            //{
            //    if (HttpContext.Current.Request.Files.Count > 0)
            //    {
            //        var file = HttpContext.Current.Request.Files[0];
            //        actualFileName = file.FileName;
            //        fileName = Guid.NewGuid() + Path.GetExtension(file.FileName);
            //        int size = file.ContentLength;
            //        try
            //        {
            //            string FilePath = Path.Combine(HttpContext.Current.Server.MapPath("~/Content/Files/") + fileName).ToString();
            //            file.SaveAs(Path.Combine(HttpContext.Current.Server.MapPath("~/Content/Files/"), fileName));
            //            Issue.FilePath = FilePath;
            //        }
            //        catch (Exception)
            //        {
            //            Message = "File upload failed! Please try again";
            //        }
            //    }
            //}

            // insert/update issue ticket
            if (Issu.IssueId != 0)
            {
                var resUpdate = bal.Manage(bal.Filter_Update, Issu);
                if (resUpdate)
                {
                    return(this.Request.CreateResponse(HttpStatusCode.OK, new { Message = "Issue Ticket Updated", Value = 1 }));
                }
                else
                {
                    return(Request.CreateErrorResponse(HttpStatusCode.NotFound, "Ticket Not Updated"));
                }
            }
            else
            {
                var resSave = bal.Manage(bal.Filter_Insert, Issu);
                if (resSave)
                {
                    return(this.Request.CreateResponse(HttpStatusCode.OK, new { Message = "New Ticket Created", Value = 1 }));
                }
                else
                {
                    return(Request.CreateErrorResponse(HttpStatusCode.NotFound, "Ticket Not Created"));
                }
            }
        }