예제 #1
0
        private IEnumerable <FileCard> GetFileCardsFromRows(DataRowCollection rows)
        {
            var fileCards = new List <FileCard>();

            foreach (DataRow row in rows)
            {
                var fileCard = new FileCard
                {
                    File = new File
                    {
                        Id           = Convert.ToInt32(row["FileId"]),
                        Name         = row["FileName"].ToString(),
                        Size         = Convert.ToDouble(row["Size"]),
                        Description  = row["Description"].ToString(),
                        CategoryId   = Convert.ToInt32(row["FileCategoryId"]),
                        FileUrlId    = Convert.ToInt32(row["FileUrlId"]),
                        DownloadDate = Convert.ToDateTime(row["DownloadDate"]),
                        FileAccessId = Convert.ToInt32(row["FileAccessId"]),
                        UserId       = Convert.ToInt32(row["UserId"])
                    },
                    FileAccess = new FileAccess
                    {
                        Id   = Convert.ToInt32(row["FileAccessId"]),
                        Name = row["FileAccessName"].ToString()
                    },
                    FileCategory = new FileCategory
                    {
                        Id   = Convert.ToInt32(row["FileCategoryId"]),
                        Name = row["FileCategoryName"].ToString()
                    },
                    FileUrl = new FileUrl
                    {
                        Id  = Convert.ToInt32(row["FileUrlId"]),
                        Url = row["FileUrlName"].ToString()
                    }
                };
                fileCards.Add(fileCard);
            }
            return(fileCards);
        }
        public HttpResponseMessage Create(HttpRequestMessage request)
        {
            return(CreateHttpResponse(request, () =>
            {
                HttpResponseMessage response = null;
                var form = HttpContext.Current.Request.Unvalidated.Form["botId"];
                var botId = new JavaScriptSerializer {
                    MaxJsonLength = Int32.MaxValue, RecursionLimit = 100
                }.Deserialize <int>(form);
                var file = HttpContext.Current.Request.Files[0];
                if (file.ContentLength > 0)
                {
                    Guid id = Guid.NewGuid();
                    string extentsion = new FileInfo(file.FileName).Extension.ToLower();
                    string fileName = id + "-" + new FileInfo(file.FileName).Name;

                    file.SaveAs(Path.Combine(HttpContext.Current.Server.MapPath("~/File/Images/")
                                             + CommonConstants.PathImage + "/" + fileName));

                    var FileCard = new FileCard()
                    {
                        Name = fileName,
                        Type = "image",
                        Url = "File/Images/" + CommonConstants.PathImage + "/" + fileName,
                        BotID = botId,
                    };
                    var FileCardReturn = _FileCardService.Add(ref FileCard);
                    response = request.CreateResponse(HttpStatusCode.OK, FileCardReturn);
                }
                else
                {
                    response = request.CreateErrorResponse(HttpStatusCode.BadRequest, "No Implement");
                }

                return response;
            }));
        }
 public void Update(FileCard file)
 {
     _FileCardRepository.Update(file);
 }