public async Task <HttpResponseMessage> CreateAsync(MT_Incident IMD) { Db = con.SurgeryCenterDb(IMD.Slug); IncidentResponse Response = new IncidentResponse(); try { UniqueID = con.GetUniqueKey(); IMD.Inci_Unique_ID = UniqueID; IMD.Inci_Create_Date = con.ConvertTimeZone(IMD.Inci_TimeZone, Convert.ToDateTime(IMD.Inci_Create_Date)); IMD.Inci_Modify_Date = con.ConvertTimeZone(IMD.Inci_TimeZone, Convert.ToDateTime(IMD.Inci_Modify_Date)); DocumentReference docRef = Db.Collection("MT_Incident").Document(UniqueID); WriteResult Result = await docRef.SetAsync(IMD); if (Result != null) { Response.Status = con.StatusSuccess; Response.Message = con.MessageSuccess; Response.Data = IMD; } else { Response.Status = con.StatusNotInsert; Response.Message = con.MessageNotInsert; Response.Data = null; } } catch (Exception ex) { Response.Status = con.StatusFailed; Response.Message = con.MessageFailed + ", Exception : " + ex.Message; } return(ConvertToJSON(Response)); }
//[Authorize(Roles = "Admin")] public async Task <HttpResponseMessage> GetAsync(MT_Incident IMD) { Db = con.SurgeryCenterDb(IMD.Slug); IncidentResponse Response = new IncidentResponse(); try { MT_Incident Inci = new MT_Incident(); Query docRef = Db.Collection("MT_Incident").WhereEqualTo("Inci_Unique_ID", IMD.Inci_Unique_ID).WhereEqualTo("Inci_Is_Deleted", false); QuerySnapshot ObjQuerySnap = await docRef.GetSnapshotAsync(); if (ObjQuerySnap != null) { Inci = ObjQuerySnap.Documents[0].ConvertTo <MT_Incident>(); } Response.Status = con.StatusSuccess; Response.Message = con.MessageSuccess; } catch (Exception ex) { Response.Status = con.StatusFailed; Response.Message = con.MessageFailed + ", Exception : " + ex.Message; } return(ConvertToJSON(Response)); }
//[Authorize(Roles ="SAdmin")] public async Task <HttpResponseMessage> GetDeletedList(MT_Incident IMD) { Db = con.SurgeryCenterDb(IMD.Slug); IncidentResponse Response = new IncidentResponse(); try { List <MT_Incident> AnesList = new List <MT_Incident>(); Query docRef = Db.Collection("MT_Incident").WhereEqualTo("Inci_Is_Deleted", true); QuerySnapshot ObjQuerySnap = await docRef.GetSnapshotAsync(); if (ObjQuerySnap != null) { foreach (DocumentSnapshot Docsnapshot in ObjQuerySnap.Documents) { AnesList.Add(Docsnapshot.ConvertTo <MT_Incident>()); } Response.DataList = AnesList.OrderBy(o => o.Inci_Name).ToList(); } Response.Status = con.StatusSuccess; Response.Message = con.MessageSuccess; } catch (Exception ex) { Response.Status = con.StatusFailed; Response.Message = con.MessageFailed + ", Exception : " + ex.Message; } return(ConvertToJSON(Response)); }
public async Task <HttpResponseMessage> Remove(MT_Incident IMD) { Db = con.SurgeryCenterDb(IMD.Slug); IncidentResponse Response = new IncidentResponse(); try { DocumentReference docRef = Db.Collection("MT_Incident").Document(IMD.Inci_Unique_ID); WriteResult Result = await docRef.DeleteAsync(); if (Result != null) { Response.Status = con.StatusSuccess; Response.Message = con.MessageSuccess; Response.Data = null; } else { Response.Status = con.StatusNotDeleted; Response.Message = con.MessageNotDeleted; Response.Data = null; } } catch (Exception ex) { Response.Status = con.StatusFailed; Response.Message = con.MessageFailed + ", Exception : " + ex.Message; } return(ConvertToJSON(Response)); }
public async Task <HttpResponseMessage> UpdateAsync(MT_Incident IMD) { Db = con.SurgeryCenterDb(IMD.Slug); IncidentResponse Response = new IncidentResponse(); try { Dictionary <string, object> initialData = new Dictionary <string, object> { { "Inci_Name", IMD.Inci_Name }, { "Inci_Type", IMD.Inci_Type }, { "Inci_Modify_Date", con.ConvertTimeZone(IMD.Inci_TimeZone, Convert.ToDateTime(IMD.Inci_Modify_Date)) } }; DocumentReference docRef = Db.Collection("MT_Incident").Document(IMD.Inci_Unique_ID); WriteResult Result = await docRef.UpdateAsync(initialData); if (Result != null) { Response.Status = con.StatusSuccess; Response.Message = con.MessageSuccess; Response.Data = IMD; } else { Response.Status = con.StatusNotUpdate; Response.Message = con.MessageNotUpdate; Response.Data = null; } } catch (Exception ex) { Response.Status = con.StatusFailed; Response.Message = con.MessageFailed + ", Exception : " + ex.Message; } return(ConvertToJSON(Response)); }