Guest User

Guest User

  • Tech Writer
  • 611
  • 128k

How to store image name in database.

Apr 29 2020 6:59 AM
It's me user detail insert  code api.
  1. public UserResponse AddUserDetail(UserProfileDetails obj_Parameter)  
  2. {  
  3. UserResponse obj_Response = new UserResponse();  
  4. UserProfileDetail obj_UserProfileDetail = new UserProfileDetail();  
  5. try  
  6. {  
  7. var check_UserDetail = _db.UserProfileDetails.Where(x => x.UserId == obj_Parameter.UserId /*&& x.CardNumber == obj_Parameter.CardNumber*/).FirstOrDefault();  
  8. if (check_UserDetail != null)  
  9. {  
  10. obj_Response.Response = 2;  
  11. obj_Response.ErrorMessage = "User Already exists";  
  12. }  
  13. else  
  14. {  
  15. obj_UserProfileDetail.FirstName = obj_Parameter.FirstName;  
  16. obj_UserProfileDetail.PhoneNumber = obj_Parameter.PhoneNumber;  
  17. obj_UserProfileDetail.Address = obj_Parameter.Address;  
  18. obj_UserProfileDetail.CityId = obj_Parameter.CityId;  
  19. obj_UserProfileDetail.State = obj_Parameter.State;  
  20. obj_UserProfileDetail.Pincode = obj_Parameter.Pincode;  
  21. obj_UserProfileDetail.Description = obj_Parameter.Description;  
  22. obj_UserProfileDetail.CardNumber = obj_Parameter.CardNumber;  
  23. obj_UserProfileDetail.CardExpiry = obj_Parameter.CardExpiry;  
  24. obj_UserProfileDetail.CVV = obj_Parameter.CVV;  
  25. obj_UserProfileDetail.UserImage = obj_Parameter.UserImage;  
  26. obj_UserProfileDetail.UserId = obj_Parameter.UserId;  
  27. _db.UserProfileDetails.Add(obj_UserProfileDetail);  
  28.  _db.SaveChanges();  
Its me image upload api.
  1. {  
  2.           UserResponse obj_Response = new UserResponse();  
  3.          // UserProfileDetail obj_UserProfileDetail = new UserProfileDetail();  
  4.           //UserProfileDetails obj_profile = new UserProfileDetails();  
  5.           var file = HttpContext.Current.Request.Files.Count > 0 ?  
  6.           HttpContext.Current.Request.Files[0] : null;  
  7.           if (!Request.Content.IsMimeMultipartContent())  
  8.           {  
  9.               throw new HttpResponseException(HttpStatusCode.UnsupportedMediaType);  
  10.           }  
  11.           try  
  12.           {  
  13.               if (file != null && file.ContentLength > 0)  
  14.               {  
  15.                   var fileName = Path.GetFileName(file.FileName);  
  16.                   var path = Path.Combine(  
  17.                       HttpContext.Current.Server.MapPath("~/User_Images/"),  
  18.                       fileName  
  19.                   );  
  20.                   file.SaveAs(path);  
  21.                    
  22.                   obj_Response.Response = 1;  
  23.                   obj_Response.ErrorMessage = "Error Not Found";  
  24.               }  
  25.               else  
  26.               {  
  27.                   obj_Response.Response = 2;  
  28.                   obj_Response.ErrorMessage = "Profie was not successfully uploaded";  
  29.               }  
  30.           }  
  31.           catch (System.Exception ex)  
  32.           {  
  33.               obj_Response.Response = 0;  
  34.               obj_Response.ErrorMessage = ex.InnerException.ToString();  
  35.           }  
  36.           return obj_Response;  
  37.       }
How to save image name in the database . By using multipart form data.Please solve

Answers (2)