public async Task <HttpResponseMessage> UploadPlayerImage(int playerid)
        {
            Dictionary <string, object> dict = new Dictionary <string, object>();

            try
            {
                var httpRequest = HttpContext.Current.Request;
                foreach (string file in httpRequest.Files)
                {
                    HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.Created);
                    var postedFile = httpRequest.Files[file];
                    if (postedFile != null && postedFile.ContentLength > 0)
                    {
                        int            MaxContentLength      = 1024 * 1024 * 1; //Size = 1 MB
                        IList <string> AllowedFileExtensions = new List <string> {
                            ".jpg", ".gif", ".png"
                        };
                        var ext = postedFile.FileName.Substring(postedFile.FileName.LastIndexOf('.'));
                        var originalFilename = Path.GetFileName(postedFile.FileName);
                        var extension        = ext.ToLower();
                        if (!AllowedFileExtensions.Contains(extension))
                        {
                            var message = string.Format("Please Upload image of type .jpg,.gif,.png.");
                            dict.Add("error", message);
                            return(Request.CreateResponse(HttpStatusCode.BadRequest, dict));
                        }
                        else if (postedFile.ContentLength > MaxContentLength)
                        {
                            var message = string.Format("Please Upload a file upto 1 mb.");
                            dict.Add("error", message);
                            return(Request.CreateResponse(HttpStatusCode.BadRequest, dict));
                        }
                        else
                        {
                            string fileId = Guid.NewGuid().ToString().Replace("-", "");
                            //if needed write the code to update the table
                            var filePath = HttpContext.Current.Server.MapPath("~/PlayerImages/" + fileId + originalFilename);
                            postedFile.SaveAs(filePath);

                            var playerinfo = dbcontext.Players.Where(p => p.Id == playerid).FirstOrDefault();
                            playerinfo.ImagePath = Convert.ToString("http://idtp285/PlayerImages/" + fileId + originalFilename);
                            dbcontext.Players.Attach(playerinfo);
                            dbcontext.Entry(playerinfo).Property(x => x.ImagePath).IsModified = true;
                            dbcontext.SaveChanges();
                        }
                    }
                    var message1 = string.Format("Image Updated Successfully.");
                    return(Request.CreateErrorResponse(HttpStatusCode.Created, message1));;
                }
                var res = string.Format("Please Upload a image.");
                dict.Add("error", res);
                return(Request.CreateResponse(HttpStatusCode.NotFound, dict));
            }
            catch (Exception ex)
            {
                var res = string.Format("some Message");
                dict.Add("error", res);
                return(Request.CreateResponse(HttpStatusCode.NotFound, dict));
            }
        }
 public void UpdateModel(T model)
 {
     _context.Entry(model).State = EntityState.Modified;
 }