// GET: Project/Create
        public ActionResult Create()
        {
            if (Session["user_type"].Equals("GST") || Session["user_type"].Equals("CMP"))
            {
                return(RedirectToAction("../Home/Index"));
            }
            ProjectRegErr err = new ProjectRegErr();

            ViewBag.Categories = db.CategoriesLists;

            return(View(err));
        }
        public async Task <ActionResult> Create(FormCollection collection)
        {
            if (Session["user_type"].Equals("GST") || Session["user_type"].Equals("CMP"))
            {
                return(RedirectToAction("../Home/Index"));
            }

            bool          flag = false;
            ProjectRegErr err  = new ProjectRegErr();

            ViewBag.Categories = db.CategoriesLists;

            Project p = new Project();

            p.Name            = Request.Form["name"];
            p.ProjectOverview = Request.Form["projectoverview"];
            p.ProjectHelp     = Request.Form["projecthelp"];
            p.TeamLooking     = Request.Form["teamlooking"];
            p.CreatedBy       = Session["user_id"].ToString();


            if (string.IsNullOrWhiteSpace(Request.Form["category"]))
            {
                flag         = true;
                err.Category = "You must select the category in which project belongs";
            }
            else
            {
                p.C_Id = Convert.ToInt32(Request.Form["category"]);
            }
            HttpPostedFileBase pic = Request.Files["pic"];

            if ((pic != null) && (pic.ContentLength > 0) && !string.IsNullOrWhiteSpace(pic.FileName))
            {
                byte[] picBytes = new byte[pic.ContentLength];
                pic.InputStream.Read(picBytes, 0, Convert.ToInt32(pic.ContentLength));
                p.Pic = picBytes;
            }
            else
            {
                flag    = true;
                err.Pic = "You must upload a pic related to the project as a .jpg or a .png file";
            }

            if (string.IsNullOrWhiteSpace(p.Name))
            {
                flag     = true;
                err.Name = "You must give the project a name";
            }
            if (string.IsNullOrWhiteSpace(p.ProjectHelp))
            {
                flag            = true;
                err.ProjectHelp = "You must give a description on where the project needs help";
            }
            if (string.IsNullOrWhiteSpace(p.ProjectOverview))
            {
                flag = true;
                err.ProjectOverview = "You must give a detailed overview of the project and the work do be done in it";
            }
            if (string.IsNullOrWhiteSpace(p.TeamLooking))
            {
                flag            = true;
                err.TeamLooking = "You must give a description on what kind of team are you looking for";
            }

            if (flag)
            {
                err.p = p;
                return(View(err));
            }

            try
            {
                string response = "";

                using (var client = new HttpClient())
                {
                    client.BaseAddress = new Uri(Baseurl);

                    client.DefaultRequestHeaders.Clear();

                    //Define request data format
                    client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));

                    //Sending request to find web api REST service resource GetAllEmployees using HttpClient

                    HttpResponseMessage Res = await client.PostAsJsonAsync("api/projectsAPI/", p);

                    //Checking the response is successful or not which is sent using HttpClient
                    if (Res.IsSuccessStatusCode)
                    {
                        //Storing the response details recieved from web api
                        var Response = Res.Content.ReadAsStringAsync().Result;

                        //Deserializing the response recieved from web api and storing into the Employee list
                        response = JsonConvert.DeserializeObject <string>(Response);
                    }
                }

                if (response.Equals("exists"))
                {
                    err.p = p;
                    return(View(err));
                }
                else
                {
                    return(RedirectToAction("../Student/Projects"));
                }
            }
            catch
            {
                err.p = p;
                return(View(err));
            }
        }