public async Task <ActionResult <schoolIndicatorPictureRepository> > Get() //public async Task<ActionResult<pictureRepoitoryModel>> Get() { List <repositoryDetailList> repositoryDetailList = new List <repositoryDetailList>(); repositoryDetailList image1 = new repositoryDetailList { current_date = DateTime.Now.ToString(), picture_latitude = 11.11, picture_logitude = 22.22, picture_comment = "Picure Comments", picture_data = new sbyte[] { -1, 2, 3, 4, 5, 6, 7 }, }; repositoryDetailList.Add(image1); repositoryDetailList.Add(image1); pictureRepoitoryModel pictureRepoitory = new pictureRepoitoryModel { school_id = 1, indicatorID = 29, current_date = DateTime.Now.ToString(), pr_id = 1, picture_count = 5, // repositoryDetailList= repositoryDetailList }; List <pictureRepoitoryModel> IndicatorPictureRepository = new List <pictureRepoitoryModel>(); IndicatorPictureRepository.Add(pictureRepoitory); //schoolIndicatorPictureRepository.Add(pictureRepoitory); List <PictureRepository> schoolIndicatorPictureRepository = new List <PictureRepository>(); PictureRepository SchoolIndicatorRepository = new PictureRepository { pictureRepoitoryModel = pictureRepoitory, repositoryDetailList = repositoryDetailList }; schoolIndicatorPictureRepository.Add(SchoolIndicatorRepository); schoolIndicatorPictureRepository schoolIndicatorPictureRepositoryList = new schoolIndicatorPictureRepository() { schoolIndicatorPictureRepositoryList = schoolIndicatorPictureRepository }; return(schoolIndicatorPictureRepositoryList); }
public async Task <ActionResult <pictureRepoitoryModel> > Post(schoolIndicatorPictureRepository schoolIndicatorPictureRepositoryList) { bool status = true; string message = "Success"; bool isDuplicate = false; // List<IndicatorDevApp> indicatorDevAppList = new List<IndicatorDevApp>(); foreach (var RepoList in schoolIndicatorPictureRepositoryList.schoolIndicatorPictureRepositoryList) { var repo = RepoList.pictureRepoitoryModel; //Check if record already exist if (IndicatorTrackingExists(repo.school_id, repo.indicatorID)) { // status = false; message = "Record Already Exist of School ID: " + repo.school_id + " and Indicator ID:" + repo.indicatorID; //return Conflict(); //return Ok(new { status, message }); isDuplicate = true; } IndicatorTracking indicatorTracking = new IndicatorTracking { IndicatorID = repo.indicatorID, SchoolID = repo.school_id, DateOfUpload = Convert.ToDateTime(repo.current_date), IsUpload = true, ReUpload = false, Verified = false, CreateDate = DateTime.Now, TotalFilesUploaded = repo.picture_count, }; if (isDuplicate) { indicatorTracking = _context.IncdicatorTracking.First(a => a.SchoolID == repo.school_id && a.IndicatorID == repo.indicatorID); } else { _context.Add(indicatorTracking); } var school = _context.Schools.Find(repo.school_id); if (school.NewConstruction && repo.indicatorID < 35 && !isDuplicate) { school.CurrentStage += 1; } if (school.RepairRennovation && repo.indicatorID > 35 && !isDuplicate) { school.RepairRennovationStatus += 1; } _context.Update(school); short i = 1; // string District = _context.Schools.Include(a => a.UC.Tehsil.District) .Where(a => a.SchoolID == repo.school_id) .Select(a => a.UC.Tehsil.District.DistrictName).FirstOrDefault(); //string var rootPath = Path.Combine( Directory.GetCurrentDirectory(), "wwwroot"); //string sPath = Path.Combine(rootPath + District + "/" + iID + "/", sID.ToString()); string sPath = Path.Combine("\\Documents\\DevelopmentApp\\" + District + "/" + repo.indicatorID + "/", repo.school_id.ToString()); if (isDuplicate) { sPath = Path.Combine("\\Documents\\DevelopmentApp\\_Duplicate\\" + District + "/" + repo.indicatorID + "/", repo.school_id.ToString()); } if (!System.IO.Directory.Exists(rootPath + sPath) & RepoList.repositoryDetailList.Any()) { System.IO.Directory.CreateDirectory(rootPath + sPath); } List <IndicatorDevApp> IndicatorDevAppList = new List <IndicatorDevApp>(); foreach (var repoDetail in RepoList.repositoryDetailList) { //byte[] byteImage = new byte[repoDetail.picture_data.Length]; //Buffer.BlockCopy(repoDetail.picture_data, 0, byteImage, 0, repoDetail.picture_data.Length); string FullPathWithFileName = Path.Combine(rootPath + sPath, repo.school_id + "-" + i + ".jpg"); IndicatorDevApp indicatorDevApp = new IndicatorDevApp { SchoolID = repo.school_id, IndicatorID = repo.indicatorID, ImagePath = Path.Combine(sPath, repo.school_id + "-" + i + ".jpg"), //ImageByte = repoDetail.picture_path, //ImagePath= repoDetail.picture_path, Longitude = repoDetail.picture_logitude, Latitude = repoDetail.picture_latitude, DateTime = Convert.ToDateTime(repoDetail.current_date), SyncDate = DateTime.Now, Remarks = repoDetail.picture_comment, ImageID = i++, }; _context.Add(indicatorDevApp); using (MemoryStream ms = new MemoryStream(Convert.FromBase64String(repoDetail.picture_path))) { using (Bitmap bm2 = new Bitmap(ms)) { //bm2.SetPropertyItem() Geotag(bm2, repoDetail.picture_latitude, repoDetail.picture_logitude, Convert.ToDateTime(repoDetail.current_date)) .Save(FullPathWithFileName); } } } } try { if (!isDuplicate) { await _context.SaveChangesAsync(); } } catch (Exception ex) { //if (IndicatorTrackingExists(repo.school_id, repo.indicatorID)) //{ status = false; message = "Data mis matched from server"; //return Conflict(); //} //else //{ // throw; //} } return(Ok(new { status, message })); // return CreatedAtAction("GetIndicatorTracking", new { id = indicatorTracking.SchoolID }, indicatorTracking); }