public async Task <MisSaveResponse> DeleteMisArtifactData(SearchMisReqGet request) { mMISMapping mMis = new mMISMapping(); List <string> Roles = new List <string>(); MisSaveResponse response = new MisSaveResponse(); try { mMis = _MongoContext.mMISMapping.AsQueryable().Where(x => x.ItemType == request.TypeName && x.Item == request.Item && x.UserGroups.Contains(request.RoleName)).FirstOrDefault(); if (mMis != null) { Roles.AddRange(mMis.UserGroups); mMis.UserGroups.Clear(); Roles.ForEach(x => { if (String.Compare(x, request.RoleName, true) != 0) { mMis.UserGroups.Add(x); } }); } await _MongoContext.mMISMapping.UpdateOneAsync(Builders <mMISMapping> .Filter.Eq("_Id", mMis._Id), Builders <mMISMapping> .Update.Set("UserGroups", mMis.UserGroups)); response.Response.Status = "Success"; response.Response.StatusMessage = "Deleted Successfully"; } catch (Exception ex) { Console.WriteLine(ex.Message); response.Response.Status = "Failure"; } return(response); }
public async Task <MisSaveResponse> SaveMisData(SearchMisReqGet request) { mMISMapping mMis = new mMISMapping(); mMISMapping mMisNew = new mMISMapping(); MisSaveResponse response = new MisSaveResponse(); try { mMis = _MongoContext.mMISMapping.AsQueryable().Where(x => x.ItemType == request.TypeName && x.Item.ToLower() == request.Item.ToLower().Trim()).FirstOrDefault(); if (mMis != null) { mMis.UserGroups.Add(request.RoleName); await _MongoContext.mMISMapping.UpdateOneAsync(Builders <mMISMapping> .Filter.Eq("_Id", mMis._Id), Builders <mMISMapping> .Update.Set("UserGroups", mMis.UserGroups)); response.Id = mMis._Id; response.TypeName = mMis.ItemType; response.Item = mMis.Item; response.ItemUrl = mMis.ItemUrl; response.Users = mMis.UserGroups; response.ItemSeq = mMis.ItemSeq; response.Response.Status = "Success"; response.Response.StatusMessage = "Successfully Updated Data"; } if (mMis == null) { var Sequence = _MongoContext.mMISMapping.AsQueryable().Max(x => x.ItemSeq); mMisNew.ItemType = request.TypeName; mMisNew.Item = request.Item.Trim(); mMisNew.ItemSeq = (Sequence + 1); mMisNew.UserGroups.Add(request.RoleName); await _MongoContext.mMISMapping.InsertOneAsync(mMisNew); response.Id = mMisNew._Id; response.TypeName = mMisNew.ItemType; response.Item = mMisNew.Item; response.ItemUrl = mMisNew.ItemUrl; response.Users = mMisNew.UserGroups; response.ItemSeq = mMisNew.ItemSeq; response.Response.Status = "Success"; response.Response.StatusMessage = "Successfully Inserted Data"; } } catch (Exception ex) { Console.WriteLine(ex.Message); response.Response.Status = "Failure"; } return(response); }