コード例 #1
0
ファイル: WallsController.cs プロジェクト: jcarroll2007/Faces
        public IHttpActionResult PutWall(int id, Wall wall)
        {
            if (!ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }

            if (id != wall.Id)
            {
                return BadRequest();
            }

            db.Entry(wall).State = EntityState.Modified;

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!WallExists(id))
                {
                    return NotFound();
                }
                else
                {
                    throw;
                }
            }

            return StatusCode(HttpStatusCode.NoContent);
        }
コード例 #2
0
        public async Task<HttpResponseMessage> PostFormData()
        {
            // Check if the request contains multipart/form-data.
            if (!Request.Content.IsMimeMultipartContent())
            {
                throw new HttpResponseException(HttpStatusCode.UnsupportedMediaType);
            }
            //    ~/App_Data/profile
            string root = HttpContext.Current.Server.MapPath("~/App_Data/");
            //string root = HttpContext.Current.Server.MapPath("/services/pictures/wall");
            var provider = new MultipartFormDataStreamProvider(root);

            try
            {
                // Read the form data.
                await Request.Content.ReadAsMultipartAsync(provider);

                // This illustrates how to get the file names.
                foreach (MultipartFileData file in provider.FileData)
                {
                    string filename = file.Headers.ContentDisposition.Name;
                    if (filename.StartsWith("\"") && filename.EndsWith("\""))
                    {
                        filename = filename.Trim('"');
                    }
                    if (filename.Contains(@"/") || filename.Contains(@"\"))
                    {
                        filename = Path.GetFileName(filename);
                    }

                    string[] idholder = filename.Split(':');

                    var newWall = new Wall();
                    newWall.UserId = Convert.ToInt32(idholder[0]);
                    newWall.PosterId = Convert.ToInt32(idholder[1]);
                    newWall.PostTime = DateTime.Now;
                    newWall.Message = "";
                    db.Walls.Add(newWall);           
                    db.SaveChanges();

                    filename = newWall.Id + ".jpeg";

                    string tempUrl = "http://robertryanmorris.com/services/pictures/wall/" + filename;

                    if (File.Exists(Path.Combine(root, filename).ToString()))
                    {
                        File.Delete(Path.Combine(root, filename).ToString());
                    }

                    File.Move(file.LocalFileName, Path.Combine(root, filename));

                    newWall.Picture = tempUrl;

                    
                    db.SaveChanges();

                    return Request.CreateResponse(HttpStatusCode.OK, tempUrl);

                    //Trace.WriteLine(file.Headers.ContentDisposition.FileName);
                    //Trace.WriteLine("Server file path: " + file.LocalFileName);

                }
                return Request.CreateResponse(HttpStatusCode.OK);
            }
            catch (System.Exception e)
            {
                return Request.CreateErrorResponse(HttpStatusCode.InternalServerError, e);
            }
        }
コード例 #3
0
ファイル: WallsController.cs プロジェクト: jcarroll2007/Faces
        public IHttpActionResult PostWall(Wall wall)
        {
            if (!ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }

            db.Walls.Add(wall);
            db.SaveChanges();

            return CreatedAtRoute("DefaultApi", new { id = wall.Id }, wall);
        }
コード例 #4
0
ファイル: ModelFactory.cs プロジェクト: jcarroll2007/Faces
        public static Wall ParseWallModelToEntity(WallModel model)
        {
            var entity = new Wall();
            entity.Id = model.Id;
            entity.UserId = model.Id;
            entity.PosterId = model.Id;
            entity.Message = model.Message;
            entity.Picture = model.Picture;
            entity.PostTime = model.PostTime;

            foreach (var m in model.PostTags)
            {
                WallPostTagsTable temp = new WallPostTagsTable();
                temp.Tag = m;
                entity.PostTags.Add(temp);
            }

            foreach (var c in model.Comments)
            {
                entity.Comments.Add(ParseCommentModelToEntity(c));
            }

            return entity;
        }
コード例 #5
0
ファイル: ModelFactory.cs プロジェクト: jcarroll2007/Faces
        public static WallModel ParseWallEntityToModel(Wall u)
        {
            var model = new WallModel();
            model.Id = u.Id;
            model.UserId = u.UserId;
            model.UserFirstName = u.User.FirstName;
            model.UserLastName = u.User.LastName;
            model.PosterId = u.PosterId;
            model.PosterFirstName = u.WhoPosted.FirstName;
            model.PosterLastName = u.WhoPosted.LastName;
            model.Message = u.Message;
            model.Picture = u.Picture;
            model.PostTime = u.PostTime;

            foreach (var m in u.PostTags)
            {
                WallPostTagsTable temp = new WallPostTagsTable();
                temp = m;
                model.PostTags.Add(temp.Tag);
            }

            foreach (var m in u.Comments)
            {
                model.Comments.Add(ParseCommentEntityToModel(m));
            }

            return model;
        }