Esempio n. 1
0
        public HttpResponseMessage UpdateProfile([FromBody] SupervisorModel objSupervisorModel)
        {
            IP = System.Configuration.ConfigurationManager.AppSettings["IP"];
            var re      = Request;
            var headers = re.Headers;

            if (headers.Contains("token"))
            {
                token = headers.GetValues("token").First();
            }

            var result = Authtoken.checkToken(token);

            if (result == true)
            {
                if (objSupervisorModel.base64image == null)
                {
                    string pic = objSupervisorModel.profilePic;
                    objSupervisorModel.profilePic = pic.Replace(IP, "");
                    objSupervisorDL.updateProfile(objSupervisorModel);
                    dt = objSupervisorDL.selectbyUserid(objSupervisorModel);

                    foreach (DataRow row in dt.Rows)
                    {
                        string url = dt.Rows[0]["profilePic"].ToString();

                        //need to set value to NewColumn column
                        row["profilePic"] = IP + url;
                    }
                    var resp = Request.CreateResponse <ResponseModel>(HttpStatusCode.OK,
                                                                      new ResponseModel()
                    {
                        message = "Your profile Updated successfully", output = dt, statuscode = Convert.ToInt16(HttpStatusCode.OK)
                    });
                    return(resp);
                }
                else
                {
                    string baseencode = objSupervisorModel.base64image;
                    // Convert Base64 String to byte[]
                    byte[]       imageBytes = Convert.FromBase64String(baseencode);
                    MemoryStream ms         = new MemoryStream(imageBytes, 0, imageBytes.Length);

                    // Convert byte[] to Image
                    string filename = "/uploads/images/profilepics/" + Authtoken.GeneratePin() + AuthorizationToken.GetTimestamp(DateTime.Now) + ".png";
                    ms.Write(imageBytes, 0, imageBytes.Length);
                    System.Drawing.Image image = System.Drawing.Image.FromStream(ms, true);
                    image.Save(HttpContext.Current.Server.MapPath(filename), System.Drawing.Imaging.ImageFormat.Png);
                    objSupervisorModel.profilePic = filename;
                    objSupervisorDL.updateProfile(objSupervisorModel);
                    dt = objSupervisorDL.selectbyUserid(objSupervisorModel);

                    foreach (DataRow row in dt.Rows)
                    {
                        string url = dt.Rows[0]["profilePic"].ToString();

                        //need to set value to NewColumn column
                        row["profilePic"] = IP + url;
                    }

                    var resp = Request.CreateResponse <ResponseModel>(HttpStatusCode.OK,
                                                                      new ResponseModel()
                    {
                        message    = "Your profile Updated successfully",
                        output     = dt,
                        statuscode = Convert.ToInt16(HttpStatusCode.OK)
                    });
                    return(resp);
                }
            }
            else
            {
                var resp = Request.CreateResponse <ResponseModel>(HttpStatusCode.OK, new ResponseModel()
                {
                    message = "UnAuthorized", statuscode = Convert.ToInt16(HttpStatusCode.OK), error = true
                });
                return(resp);
            }
        }