public async Task <SocietyModel> GetSocietyByName(string name) { SocietyModel societyFuond = new SocietyModel(); if (isMockEnabled) { string json = System.IO.File.ReadAllText(pathFileMockup); List <SocietyModel> societies = JsonConvert.DeserializeObject <SocietyCollection>(json).Societies; societyFuond = societies.Find(f => f.Name == name); } else { var collection = _mongoDBContex.GetCollection <SocietyModel>(collectionName); FindOptions <SocietyModel> options = new FindOptions <SocietyModel> { Limit = 1 }; IAsyncCursor <SocietyModel> task = await collection.FindAsync(x => x.Name.Equals(name), options); List <SocietyModel> list = await task.ToListAsync(); societyFuond = list.FirstOrDefault(); } return(societyFuond); }
protected void btnSubmite_Click(object sender, EventArgs e) { if (Page.IsValid) { SocietyModel model; model = client.GetSocietyByID(txtSocietyName.Text, ParlourId); if (model != null && SocietyID == 0) { ShowMessage(ref lblMessage, MessageType.Danger, "Society Already Exists."); } else { model = new SocietyModel(); model.pkiSocietyID = SocietyID; model.SocietyName = txtSocietyName.Text; model.parlourid = ParlourId; model.LastModified = System.DateTime.Now; model.ModifiedUser = UserName; //================================================================ int retID = client.SaveSocietyDetails(model); SocietyID = retID; ShowMessage(ref lblMessage, MessageType.Success, "Society Details successfully saved"); BindSocietyList(); ClearControl(); } lblMessage.Visible = true; } else { ScriptManager.RegisterStartupScript(this, this.GetType(), "goToTab512", "goToTab(5)", true); } }
public async Task <IRestResponse> SaveSociety(SocietyModel society) { society.UserId = _system.User.Id; var response = await _system.InvokeMiddlewareAsync("/Society", "/SaveSociety", society, _system.Headers, Method.POST); return(response); }
public async Task <IActionResult> SaveValues([FromBody] object values, string SocietyName) { var json = values.ToString(); StrcutureSystem strcutureValues = JsonConvert.DeserializeObject <StrcutureSystem>(json); if (strcutureValues == null) { throw new Exception($"Values is missing"); } if (string.IsNullOrEmpty(SocietyName)) { throw new Exception($"Society Name is missing"); } SocietyModel society = await _societyServiceData.GetSocietyByName(SocietyName); if (society == null) { throw new Exception($"Society NOT FOUND!!"); } InstallationModel installation = await _installationServiceData.GetInstallationBySocietyId(society.Id); if (installation == null) { //Add installation = new InstallationModel { SocietyId = society.Id, Strucutres = strcutureValues }; } else { // update installation.Strucutres = UpdateStructure(installation.Strucutres, strcutureValues); } ResponseContent messageResponse = new ResponseContent() { Message = "Error saving the company" }; IActionResult response = BadRequest(messageResponse); var message = await _installationServiceData.SaveInstallation(installation); if (message != null) { var dic = new Dictionary <string, string>(); dic.Add("installation", JsonConvert.SerializeObject(values)); messageResponse = new ResponseContent("Save completed", dic); response = Ok(messageResponse); } return(response); }
public async Task <SocietyModel> SaveSociety(SocietyModel society) { if (isMockEnabled) { string json = System.IO.File.ReadAllText(pathFileMockup); List <SocietyModel> societies = JsonConvert.DeserializeObject <SocietyCollection>(json).Societies; var societyFound = await GetSocietyByName(society.Name); if (societyFound == null) { society.Id = ObjectId.GenerateNewId().ToString(); societies.Add(society); } else if (societyFound.UserId == society.UserId) { societies.Remove(societyFound); society.Id = societyFound.Id; societies.Add(society); } SocietyCollection collection = new SocietyCollection(); collection.Societies = societies; string jsonUpdate = JsonConvert.SerializeObject(collection); //write string to file System.IO.File.WriteAllText(pathFileMockup, jsonUpdate); } else { try { var collection = _mongoDBContex.GetCollection <SocietyModel>(collectionName); var societyFound = await GetSocietyByName(society.Name); if (societyFound == null) { society.Id = ObjectId.GenerateNewId().ToString(); await collection.InsertOneAsync(society); } else if (society.UserId == societyFound.UserId) { society.Id = societyFound.Id; var optionsAndReplace = new FindOneAndReplaceOptions <SocietyModel> { ReturnDocument = ReturnDocument.After }; var up = await collection.FindOneAndReplaceAsync <SocietyModel>(u => u.Id == society.Id, society, optionsAndReplace); } } catch (Exception ex) { } } return(society); }
public async Task <IActionResult> DeleteSociety([FromBody] SocietyModel society) { IActionResult response = BadRequest(); StatusCodeResult responseDeleteCollection = await _installationServiceData.DeleteInstallation(society.Id); if (responseDeleteCollection.StatusCode == HttpStatusCode.OK.GetHashCode()) { response = await _societyServiceData.DeleteSociety(society); } return(response); }
public async Task GetSocietyById(string societyId) { if (!string.IsNullOrEmpty(societyId)) { var response = await _system.InvokeMiddlewareAsync("/Society", "/GetSocietyById?SocietyId=" + societyId, null, _system.Headers, Method.GET); ResponseContent responseContent = JsonConvert.DeserializeObject <ResponseContent>(response.Content); if (response.StatusCode == HttpStatusCode.OK) { Society = JsonConvert.DeserializeObject <SocietyModel>(responseContent.Content["Society"]); } } }
public async Task <IActionResult> DeleteSociety(SocietyModel society) { ResponseContent message = new ResponseContent(); IActionResult result = BadRequest(); if (isMockEnabled) { string json = System.IO.File.ReadAllText(pathFileMockup); List <SocietyModel> societies = JsonConvert.DeserializeObject <SocietyCollection>(json).Societies; var societyFound = await GetSocietyByName(society.Name); if (societyFound != null) { societies.Remove(societyFound); message.Message = "1 row deleted"; result = Ok(message); } SocietyCollection collection = new SocietyCollection(); collection.Societies = societies; string jsonUpdate = JsonConvert.SerializeObject(collection); //write string to file System.IO.File.WriteAllText(pathFileMockup, jsonUpdate); } else { try { var collection = _mongoDBContex.GetCollection <SocietyModel>(collectionName); var societyFound = await GetSocietyByName(society.Name); if (societyFound != null) { var deleteFilter = Builders <SocietyModel> .Filter.Where(f => f.Id == society.Id); var count = await collection.DeleteOneAsync(deleteFilter); message.Message = count.DeletedCount.ToString() + " row deleted"; result = Ok(message); } } catch (Exception ex) { } } return(result); }
public void BindSocietyToUpdate() { SocietyModel model = client.EditSocietybyID(SocietyID, ParlourId); if (model == null) { Response.Write("<script>alert('Sorry!you are not authorized to perform edit on this Branch.');</script>"); } else { SocietyID = model.pkiSocietyID; txtSocietyName.Text = model.SocietyName; btnSubmite.Text = "Update"; } }
public async Task <IActionResult> SaveSociety([FromBody] SocietyModel society) { ResponseContent messageResponse = new ResponseContent() { Message = "Error saving the company" }; IActionResult response = BadRequest(messageResponse); society = await _societyServiceData.SaveSociety(society); if (society != null) { var dic = new Dictionary <string, string>(); dic.Add("society", JsonConvert.SerializeObject(society)); messageResponse = new ResponseContent("Save completed", dic); response = Ok(messageResponse); } return(response); }
public static int SaveSocietyDetails(SocietyModel model) { return(ToolsSetingDAL.SaveSocietyDetails(model)); }
public async Task <IRestResponse> DeleteSociety(SocietyModel society) { var response = await _system.InvokeMiddlewareAsync("/Society", "/DeleteSociety", society, _system.Headers, Method.POST); return(response); }