private void BuildModel(DbDataReader objDataReader, ApartmentPhotos objApartmentPhotos) { var objDataTable = objDataReader.GetSchemaTable(); foreach (DataRow dr in objDataTable.Rows) { var column = dr.ItemArray[0].ToString(); switch (column) { case "PropertyId": if (!Convert.IsDBNull(objDataReader["PropertyId"])) { objApartmentPhotos.PropertyId = Convert.ToInt32(objDataReader["PropertyId"].ToString()); } break; case "PhotoName": if (!Convert.IsDBNull(objDataReader["PhotoName"])) { objApartmentPhotos.PhotoName = objDataReader["PhotoName"].ToString(); } break; case "LandloadId": if (!Convert.IsDBNull(objDataReader["LandloadId"])) { objApartmentPhotos.LandloadId = objDataReader["LandloadId"].ToString(); } break; case "ApartmentPhotoSerial": if (!Convert.IsDBNull(objDataReader["ApartmentPhotoSerial"])) { objApartmentPhotos.ApartmentPhotoSerial = Convert.ToInt32(objDataReader["ApartmentPhotoSerial"].ToString()); } break; case "PhotoUrl": if (!Convert.IsDBNull(objDataReader["PhotoUrl"])) { objApartmentPhotos.PhotoUrl = objDataReader["PhotoUrl"].ToString(); } break; case "Status": if (!Convert.IsDBNull(objDataReader["Status"])) { objApartmentPhotos.Status = Convert.ToBoolean(objDataReader["Status"]); } break; case "EntryDate": if (!Convert.IsDBNull(objDataReader["EntryDate"])) { objApartmentPhotos.EntryDate = Convert.ToDateTime(objDataReader["EntryDate"]); } break; case "EntryBy": if (!Convert.IsDBNull(objDataReader["EntryBy"])) { objApartmentPhotos.EntryBy = objDataReader["EntryBy"].ToString(); } break; case "UpdateDate": if (!Convert.IsDBNull(objDataReader["UpdateDate"])) { objApartmentPhotos.UpdateDate = Convert.ToDateTime(objDataReader["UpdateDate"]); } break; case "UpdateBy": if (!Convert.IsDBNull(objDataReader["UpdateBy"])) { objApartmentPhotos.UpdateBy = objDataReader["UpdateBy"].ToString(); } break; default: break; } } objApartmentPhotos.IsNew = false; objApartmentPhotos.IsDirty = true; objApartmentPhotos.IsDelete = false; }
private void AddPhoto() { if (fudProPertyImage.HasFile && ddlUserWisePropertyForPicture.SelectedIndex > 0 && ddlApartmentNo.SelectedIndex > 0) { List <ApartmentPhotos> objApartmentPhotoList = null; string path = null; objUserDetail = (UserDetail)SessionUtility.SessionUtility.AmsSessionContainer.OBJ_USER_CLASS; if (SessionUtility.SessionUtility.AmsSessionContainer.OBJ_Photo_CLASS == null) { objApartmentPhotoList = new List <ApartmentPhotos>(); } else { objApartmentPhotoList = SessionUtility.SessionUtility.AmsSessionContainer.OBJ_Photo_CLASS as List <ApartmentPhotos>; } //string theFileName = DateTime.Now.ToShortDateString() + "-" + DateTime.Now.Hour + "-" + DateTime.Now.Minute + "-" + DateTime.Now.Millisecond + "-" + fudPropertyPhoto.FileName; //string path = FolderPath + theFileName; string folderPath = ConfigurationManager.AppSettings["ProfileImageUrl"];//~/UserUI/userImages/ string directoryPath = folderPath + objUserDetail.UserID.Trim() + "/Property" + ddlUserWisePropertyForPicture.SelectedValue + "/Apartment" + ddlApartmentNo.SelectedValue + "/ImgTemp"; //Server.MapPath(folderPath + "/" + objUserDetail.UserID.Trim()+"/Property"+ddlUserWisePropertyForPicture.SelectedValue +"/Apartment"+ddlApartmentNo.SelectedValue+ "/ImgTemp"); string extension = Path.GetExtension(fudProPertyImage.FileName).ToLower(); if (!Directory.Exists(System.Web.Hosting.HostingEnvironment.MapPath(directoryPath))) { Directory.CreateDirectory(System.Web.Hosting.HostingEnvironment.MapPath(directoryPath)); } if (extension != null) { path = directoryPath + "\\" + fudProPertyImage.FileName; if (File.Exists(System.Web.Hosting.HostingEnvironment.MapPath(path))) { File.Delete(System.Web.Hosting.HostingEnvironment.MapPath(path)); } fudProPertyImage.SaveAs(System.Web.Hosting.HostingEnvironment.MapPath(path)); } ApartmentPhotos objPropertyPhoto = new ApartmentPhotos(); objPropertyPhoto.ApartmentPhotoSerial = objApartmentPhotoList.Count + 1; objPropertyPhoto.PhotoName = fudProPertyImage.FileName; objPropertyPhoto.PhotoUrl = path; objPropertyPhoto.PropertyId = Convert.ToInt32(ddlUserWisePropertyForPicture.SelectedValue.Trim()); objPropertyPhoto.ApartmentId = Convert.ToInt32(ddlApartmentNo.SelectedValue.Trim()); objPropertyPhoto.LandloadId = objUserDetail.UserID.Trim(); objApartmentPhotoList.Add(objPropertyPhoto); SessionUtility.SessionUtility.AmsSessionContainer.OBJ_Photo_CLASS = objApartmentPhotoList; } else { MessageBox("Please upload a file."); } }