public HttpResponseMessage CelebrityProfile([FromBody] CelebrityPhoto user)
        {
            string message = "";

            if (ModelState.IsValid)
            {
                using (MyDbEntities db = new MyDbEntities())
                {
                    UserViewModel model = new UserViewModel();

                    var userProfile = db.CelebrityDataExtendeds.Where(a => a.CelebrityId == user.CelibrityID).FirstOrDefault();
                    //var userProfile = db.UserPhotos.Where(c => c.UploaderID == user.UserId).FirstOrDefault();

                    //model.Link = ProfilePic.Link;

                    // map user detail with profile 4to
                    return(Request.CreateResponse(HttpStatusCode.OK, userProfile));
                    // create the user profile and load it in the home page of mobile app
                }
            }
            else
            {
                message = "Connection Error! Try Again";
                return(Request.CreateResponse(HttpStatusCode.BadRequest, message));
            }
        }
        public string CelebrityPhoto([FromBody] CelebrityPhoto model)
        {
            if (ModelState.IsValid)
            {
                //save to database
                using (MyDbEntities db = new MyDbEntities())
                {
                    db.CelebrityPhotoes.Add(model);
                    db.SaveChanges();


                    return("Success");
                }
            }
            else
            {
                return("");
            }
        }
        public HttpResponseMessage SearchName([FromBody] CelebrityPhoto search)
        {
            string message = "";

            if (ModelState.IsValid)
            {
                using (MyDbEntities db = new MyDbEntities())
                {
                    var faceSearch = db.Celebrities.Where(a => a.CelebrityId == search.CelibrityID).ToList();
                    if (faceSearch != null)
                    {
                        return(Request.CreateResponse(HttpStatusCode.OK, faceSearch));
                    }
                    return(Request.CreateResponse(HttpStatusCode.NotFound, "Connection Error! Try Again"));
                }
            }
            else
            {
                message = "Connection Error! Try Again";
                return(Request.CreateResponse(HttpStatusCode.BadRequest, message));
            }
        }
        public async Task <ActionResult> NewCelebrity(CreateCelebrityViewModel celebrity)
        {
            string             message;
            int                id;
            Face0              faceAPI = new Face0();
            HttpPostedFileBase file    = celebrity.imageBrowes;
            //
            Image        i  = Image.FromStream(file.InputStream, true, true);
            MemoryStream ms = new MemoryStream();

            i.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg);
            byte[] imgData = ms.ToArray();

            using (var fileStream = new MemoryStream(imgData))
            {
                int s = await faceAPI.searchFirst(fileStream);

                if (s == 0)
                {
                    ViewBag.Status  = true;
                    ViewBag.Message = "no one detected";
                    return(View());
                }
                else if (s == 1)
                {
                    ViewBag.Status  = true;
                    ViewBag.Message = "more than one person detected";
                    return(View());
                }
                else if (s == 2)
                {
                    ViewBag.Status  = true;
                    ViewBag.Message = "there is an existing person";
                    return(View());
                }
            }
            //
            try
            {
                Celebrity celebrityModel = new Celebrity();

                celebrityModel.FirstName    = celebrity.FirstName;
                celebrityModel.LastName     = celebrity.LastName;
                celebrityModel.Gender       = celebrity.Gender;
                celebrityModel.Feild        = celebrity.Feild;
                celebrityModel.Description  = celebrity.Description;
                celebrityModel.ActiveStatus = true;

                var serializer     = new JavaScriptSerializer();
                var json1          = serializer.Serialize(celebrityModel);
                var stringContent1 = new StringContent(json1, Encoding.UTF8, "application/json");

                HttpResponseMessage response = await client.PostAsync("api/Celebrity/NewCelebrity", stringContent1);

                if (response.IsSuccessStatusCode)
                {
                    id = response.Content.ReadAsAsync <int>().Result;
                    //

                    using (var fileStream = new MemoryStream(imgData))
                    {
                        string s = await faceAPI.register(imgData, id);

                        if (s != "Success")
                        {
                            ViewBag.Status  = true;
                            ViewBag.Message = s;
                            return(View());
                        }
                    }
                    //
                    DateTime dTime = DateTime.Now;
                    string   time  = dTime.ToString();
                    time = time.Replace(" ", "_") + ".jpg";

                    if (file.ContentLength > 0)
                    {
                        CloudStorageAccount storageAccount = CloudStorageAccount.Parse("DefaultEndpointsProtocol=https;AccountName=faceitphotos;AccountKey=" + ConfigurationManager.AppSettings["StorageKey"].ToString());
                        CloudBlobClient     blobClient     = storageAccount.CreateCloudBlobClient();
                        CloudBlobContainer  container      = blobClient.GetContainerReference("celebrityimages");
                        container.CreateIfNotExists();

                        CloudBlockBlob blockBlob = container.GetBlockBlobReference(id.ToString() + "_" + time);
                        //Image i = Image.FromStream(file.InputStream, true, true);
                        //MemoryStream ms = new MemoryStream();
                        //i.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg);
                        //byte[] imgData = ms.ToArray();

                        using (var fileStream = new MemoryStream(imgData))
                        {
                            await blockBlob.UploadFromStreamAsync(fileStream);
                        }
                    }
                    if (id != 0)
                    {
                        CelebrityPhoto photoModel = new CelebrityPhoto();

                        photoModel.Link        = "https://faceitphotos.blob.core.windows.net/celebrityimages/" + id + "_" + time;
                        photoModel.ProfilePic  = true;
                        photoModel.CelibrityID = id;
                        var json2          = serializer.Serialize(photoModel);
                        var stringContent2 = new StringContent(json2, Encoding.UTF8, "application/json");
                        response = await client.PostAsync("api/Celebrity/CelebrityPhoto", stringContent2);

                        if (response.IsSuccessStatusCode)
                        {
                            message = response.Content.ReadAsAsync <string>().Result;
                            if (message == "Success")
                            {
                                return(RedirectToAction("CelebrityProfile", new { id = id }));
                            }
                            else
                            {
                                ViewBag.Status  = true;
                                ViewBag.Message = "Error occured while creating profile";
                                return(View(celebrity));
                            }
                        }
                        else
                        {
                            ViewBag.Status  = true;
                            ViewBag.Message = "Error occured while creating profile";
                            return(View(celebrity));
                        }
                    }
                    else
                    {
                        ViewBag.Status  = true;
                        ViewBag.Message = "Error occured while creating profile";
                        return(View(celebrity));
                    }
                }


                return(View());
            }
            catch
            {
                ViewBag.Status  = true;
                ViewBag.Message = "Error occured while creating profile";
                return(null);
            }
        }
        public async Task <ActionResult> AddPhoto(CreateCelebrityViewModel model)
        {
            string             message = "";
            HttpPostedFileBase file    = model.imageBrowes;

            //
            Image        i  = Image.FromStream(file.InputStream, true, true);
            MemoryStream ms = new MemoryStream();

            i.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg);
            byte[] imgData = ms.ToArray();

            Face0 faceAPI = new Face0();

            using (var fileStream = new MemoryStream(imgData))
            {
                int[] face = await faceAPI.search(fileStream);

                for (int j = 0; j < 5; j++)
                {
                    if (model.CelebrityId == face[j])
                    {
                        DateTime dTime = DateTime.Now;
                        string   time  = dTime.ToString();
                        time = time.Replace(" ", "_") + ".jpg";

                        if (file.ContentLength > 0)
                        {
                            CloudStorageAccount storageAccount = CloudStorageAccount.Parse("DefaultEndpointsProtocol=https;AccountName=faceitphotos;AccountKey=" + ConfigurationManager.AppSettings["StorageKey"].ToString());
                            CloudBlobClient     blobClient     = storageAccount.CreateCloudBlobClient();
                            CloudBlobContainer  container      = blobClient.GetContainerReference("celebrityimages");
                            container.CreateIfNotExists();

                            CloudBlockBlob blockBlob = container.GetBlockBlobReference(model.CelebrityId.ToString() + "_" + time);

                            /*Image i = Image.FromStream(file.InputStream, true, true);
                             * MemoryStream ms = new MemoryStream();
                             * i.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg);
                             * byte[] imgData = ms.ToArray();*/

                            using (var fileStream2 = new MemoryStream(imgData))
                            {
                                await blockBlob.UploadFromStreamAsync(fileStream2);
                            }

                            using (MyDbEntities db = new MyDbEntities())
                            {
                                var photos = db.CelebrityPhotoes.Where(a => a.CelibrityID == model.CelebrityId).ToList();
                                foreach (var photo in photos)
                                {
                                    photo.ProfilePic = false;
                                    db.SaveChanges();
                                }
                            }
                            //
                            CelebrityPhoto photoModel = new CelebrityPhoto();
                            photoModel.Link        = "https://faceitphotos.blob.core.windows.net/celebrityimages/" + model.CelebrityId + "_" + time;
                            photoModel.ProfilePic  = true;
                            photoModel.CelibrityID = model.CelebrityId;
                            var serializer               = new JavaScriptSerializer();
                            var json2                    = serializer.Serialize(photoModel);
                            var stringContent2           = new StringContent(json2, Encoding.UTF8, "application/json");
                            HttpResponseMessage response = await client.PostAsync("api/Celebrity/CelebrityPhoto", stringContent2);

                            if (response.IsSuccessStatusCode)
                            {
                                message = response.Content.ReadAsAsync <string>().Result;
                                if (message == "Success")
                                {
                                    ViewBag.Message = "Upload Success";
                                    return(RedirectToAction("CelebrityProfile", new { id = model.CelebrityId }));
                                }
                                else
                                {
                                    ViewBag.Message = "Upload Failed";
                                    return(RedirectToAction("ViewImage", new { id = model.CelebrityId }));
                                }
                            }
                            else
                            {
                                ViewBag.Message = "Upload Failed";
                                return(RedirectToAction("ViewImage", new { id = model.CelebrityId }));
                            }
                            //
                        }
                    }
                    ViewBag.Status  = true;
                    ViewBag.Message = "not this person face";
                    return(View("ViewImage"));
                }
            }
            //


            ViewBag.Message = "Upload Failed";
            return(RedirectToAction("ViewImage", new { id = model.CelebrityId }));
        }