Beispiel #1
0
        public JsonResult UploadFile(int type, string message, string auth)
        {
            var downloadCode = _fileService.NewDownloadCode();
            var user         = _userService.GetUserByAuth(auth);

            if (user != null)
            {
                if (Request.Files.Count > 0)
                {
                    if (user.Session != null)
                    {
                        var file = Request.Files[0];
                        if (file != null && file.ContentLength > 0)
                        {
                            var fileName = downloadCode + Path.GetExtension(file.FileName);
                            var path     = Path.Combine(Server.MapPath("~/Content/Files"), fileName);
                            file.SaveAs(path);
                            _sessionService.AddFile(type, fileName, downloadCode, message, user, DateTime.Now);
                            return(Json(new { status = "OK" }, JsonRequestBehavior.AllowGet));
                        }
                        else
                        {
                            return(Json(new { status = "ERR" }, JsonRequestBehavior.AllowGet));
                        }
                    }
                    else
                    {
                        return(Json(new { status = "NO SESSION" }, JsonRequestBehavior.AllowGet));
                    }
                }
                else
                {
                    return(Json(new { status = "NO FILES" }, JsonRequestBehavior.AllowGet));
                }
            }
            else
            {
                return(Json(new { status = "WRONG AUTH" }, JsonRequestBehavior.AllowGet));
            }
        }