/// <summary> /// CreateSpirit Method inserts new record in Spirit table /// </summary> /// <param name="spiritObject"></param> /// <returns>int</returns> public int CreateSpirit(int userId, SpiritObject spiritObject) { var distillerId = _dl.GetDistillerId(userId); //define method execution return value to be false by default var retMthdExecResult = 0; if (spiritObject != null) { try { Spirit tbl = new Spirit(); tbl.Name = spiritObject.SpiritName; tbl.ProcessingReportTypeID = spiritObject.ProcessingReportTypeID; tbl.DistillerID = distillerId; if (spiritObject.Note != string.Empty && spiritObject.Note != null) { tbl.Note = spiritObject.Note; } _db.Spirit.Add(tbl); _db.SaveChanges(); retMthdExecResult = tbl.SpiritID; } catch (Exception e) { retMthdExecResult = 0; } } else { retMthdExecResult = 0; } return(retMthdExecResult); }
/// <summary> /// This method gets the list of Spirits /// </summary> /// <param name="userId"></param> /// <returns>List<SpiritObject></returns> public List <SpiritObject> GetSpiritList(int userId) { List <SpiritObject> spiritList = new List <SpiritObject>(); try { var recs = from spirit in _db.Spirit join us2Distills in _db.AspNetUserToDistiller on new { DistillerID = spirit.DistillerID } equals new { DistillerID = us2Distills.DistillerID } into us2Distills_join from us2Distills in us2Distills_join.DefaultIfEmpty() join reportTypes in _db.ProcessingReportType on spirit.ProcessingReportTypeID equals reportTypes.ProcessingReportTypeID into reportTypes_join from reportTypes in reportTypes_join.DefaultIfEmpty() where us2Distills.UserId == userId select new { SpiritID = (System.Int32?)spirit.SpiritID ?? (System.Int32?) 0, Name = spirit.Name ?? string.Empty, ProcessingReportTypeID = (System.Int32?)reportTypes.ProcessingReportTypeID ?? (System.Int32) 0, ProcessingReportTypeName = reportTypes.ProcessingReportTypeName ?? string.Empty, Note = spirit.Note ?? string.Empty }; foreach (var iter in recs) { var curSpirit = new SpiritObject(); curSpirit.SpiritId = (int)iter.SpiritID; curSpirit.SpiritName = iter.Name; curSpirit.ProcessingReportTypeID = iter.ProcessingReportTypeID; curSpirit.ProcessingReportTypeName = iter.ProcessingReportTypeName; curSpirit.Note = iter.Note; spiritList.Add(curSpirit); } } catch (Exception e) { Debug.WriteLine("Error retrieving Spirit List: " + e); } return(spiritList); }
/// <summary> /// UpdateSpirit method updates Spirit table and a note value in Notes table if Note hasn't been changed /// </summary> /// <param name="userId"></param> /// <param name="spiritObject"></param> /// <returns>bool</returns> public bool UpdateSpirit(int userId, SpiritObject spiritObject) { //define method execution return value to be false by default var retMthdExecResult = false; int distillerId = _dl.GetDistillerId(userId); if (spiritObject != null) { try { var recs = from rec in _db.Spirit where rec.SpiritID == spiritObject.SpiritId && rec.DistillerID == distillerId select rec; var item = recs.FirstOrDefault(); if (item.Name != spiritObject.SpiritName) { item.Name = spiritObject.SpiritName; } if (item.Note != spiritObject.Note) { item.Note = spiritObject.Note; } _db.SaveChanges(); retMthdExecResult = true; } catch (Exception e) { Debug.WriteLine("Failed to update spirit record : " + e); retMthdExecResult = false; } } return(retMthdExecResult); }
public JsonResult UpdateSpirit(SpiritObject spiritObject) { if (spiritObject != null) { if (User.Identity.IsAuthenticated) { int userId = User.Identity.GetUserId <int>(); if (userId > 0) { bool returnResult = _dictionary.UpdateSpirit(userId, spiritObject); if (returnResult) { string message = "Spirit dictionary record updated successfully."; return(Json(message)); } else { string message = "Failed to update spirit dictionary record!"; return(Json(message)); } } else { return(Json("Unable to find UserId!")); } } else { return(Json("Unauthenticated user!")); } } else { return(Json("something went wrong when we tried to execute updateSpirit info in the db")); } }
public JsonResult CreateSpirit(SpiritObject spiritObject) { if (spiritObject != null) { if (User.Identity.IsAuthenticated) { int userId = User.Identity.GetUserId <int>(); if (userId > 0) { int returnResult = _dictionary.CreateSpirit(userId, spiritObject); if (returnResult > 0) { string message = "Spirit dictionary record created successfully."; return(Json(message)); } else { string message = "Failed to create spirit dictionary record!"; return(Json(message)); } } else { return(Json("Unable to find UserId!")); } } else { return(Json("Unauthenticated user!")); } } else { return(Json("Back End received empty or undefined Spirit Object from the client")); } }