public HttpResponseMessage UpdateJournalVoucherLine(Entities.TrnJournalVoucherLine objJournalVoucherLine, String id, String JVId) { try { var currentUser = from d in db.MstUsers where d.UserId == User.Identity.GetUserId() select d; if (currentUser.Any()) { var currentUserId = currentUser.FirstOrDefault().Id; var userForms = from d in db.MstUserForms where d.UserId == currentUserId && d.SysForm.FormName.Equals("JournalVoucherDetail") select d; if (userForms.Any()) { if (userForms.FirstOrDefault().CanEdit) { var journalVoucher = from d in db.TrnJournalVouchers where d.Id == Convert.ToInt32(JVId) select d; if (journalVoucher.Any()) { if (!journalVoucher.FirstOrDefault().IsLocked) { var journalVoucherLine = from d in db.TrnJournalVoucherLines where d.Id == Convert.ToInt32(id) select d; if (journalVoucherLine.Any()) { var accounts = from d in db.MstAccounts.OrderBy(d => d.Account) where d.Id == objJournalVoucherLine.AccountId && d.IsLocked == true select d; if (accounts.Any()) { var articles = from d in db.MstArticles where d.Id == objJournalVoucherLine.ArticleId && d.IsLocked == true select d; if (articles.Any()) { var updateJournalVoucherLine = journalVoucherLine.FirstOrDefault(); updateJournalVoucherLine.JVId = Convert.ToInt32(JVId); updateJournalVoucherLine.BranchId = objJournalVoucherLine.BranchId; updateJournalVoucherLine.AccountId = objJournalVoucherLine.AccountId; updateJournalVoucherLine.ArticleId = objJournalVoucherLine.ArticleId; updateJournalVoucherLine.Particulars = objJournalVoucherLine.Particulars; updateJournalVoucherLine.DebitAmount = objJournalVoucherLine.DebitAmount; updateJournalVoucherLine.CreditAmount = objJournalVoucherLine.CreditAmount; updateJournalVoucherLine.APRRId = objJournalVoucherLine.APRRId; updateJournalVoucherLine.ARSIId = objJournalVoucherLine.ARSIId; updateJournalVoucherLine.IsClear = objJournalVoucherLine.IsClear; db.SubmitChanges(); return(Request.CreateResponse(HttpStatusCode.OK)); } else { return(Request.CreateResponse(HttpStatusCode.BadRequest, "The selected item has no unit conversion.")); } } else { return(Request.CreateResponse(HttpStatusCode.BadRequest, "The selected item was not found in the server.")); } } else { return(Request.CreateResponse(HttpStatusCode.NotFound, "This journal voucher line detail is no longer exist in the server.")); } } else { return(Request.CreateResponse(HttpStatusCode.BadRequest, "You cannot add new journal voucher line if the current journal voucher detail is locked.")); } } else { return(Request.CreateResponse(HttpStatusCode.NotFound, "These current journal voucher details are not found in the server. Please add new journal voucher first before proceeding.")); } } else { return(Request.CreateResponse(HttpStatusCode.BadRequest, "Sorry. You have no rights to edit and update journal voucher line in this journal voucher detail page.")); } } else { return(Request.CreateResponse(HttpStatusCode.BadRequest, "Sorry. You have no access in this journal voucher detail page.")); } } else { return(Request.CreateResponse(HttpStatusCode.BadRequest, "Theres no current user logged in.")); } } catch (Exception e) { Debug.WriteLine(e); return(Request.CreateResponse(HttpStatusCode.InternalServerError, "Something's went wrong from the server.")); } }
public HttpResponseMessage AddJournalVoucherLine(Entities.TrnJournalVoucherLine objJournalVoucherLine, String JVId) { try { var currentUser = from d in db.MstUsers where d.UserId == User.Identity.GetUserId() select d; if (currentUser.Any()) { var currentUserId = currentUser.FirstOrDefault().Id; var userForms = from d in db.MstUserForms where d.UserId == currentUserId && d.SysForm.FormName.Equals("JournalVoucherDetail") select d; if (userForms.Any()) { if (userForms.FirstOrDefault().CanAdd) { var journalVoucher = from d in db.TrnJournalVouchers where d.Id == Convert.ToInt32(JVId) select d; if (journalVoucher.Any()) { if (!journalVoucher.FirstOrDefault().IsLocked) { var accounts = from d in db.MstAccounts.OrderBy(d => d.Account) where d.Id == objJournalVoucherLine.AccountId && d.IsLocked == true select d; if (accounts.Any()) { var articles = from d in db.MstArticles where d.Id == objJournalVoucherLine.ArticleId && d.IsLocked == true select d; if (articles.Any()) { Data.TrnJournalVoucherLine newJournalVoucherLine = new Data.TrnJournalVoucherLine { JVId = Convert.ToInt32(JVId), BranchId = objJournalVoucherLine.BranchId, AccountId = objJournalVoucherLine.AccountId, ArticleId = objJournalVoucherLine.ArticleId, Particulars = objJournalVoucherLine.Particulars, DebitAmount = objJournalVoucherLine.DebitAmount, CreditAmount = objJournalVoucherLine.CreditAmount, APRRId = objJournalVoucherLine.APRRId, ARSIId = objJournalVoucherLine.ARSIId, IsClear = objJournalVoucherLine.IsClear }; db.TrnJournalVoucherLines.InsertOnSubmit(newJournalVoucherLine); db.SubmitChanges(); String newObject = at.GetObjectString(newJournalVoucherLine); at.InsertAuditTrail(currentUser.FirstOrDefault().Id, GetType().Name, MethodBase.GetCurrentMethod().Name, "NA", newObject); return(Request.CreateResponse(HttpStatusCode.OK)); } else { return(Request.CreateResponse(HttpStatusCode.BadRequest, "No Article.")); } } else { return(Request.CreateResponse(HttpStatusCode.BadRequest, "No Account.")); } } else { return(Request.CreateResponse(HttpStatusCode.BadRequest, "You cannot add new journal voucher line if the current journal voucher detail is locked.")); } } else { return(Request.CreateResponse(HttpStatusCode.NotFound, "These current journal voucher details are not found in the server. Please add new journal voucher first before proceeding.")); } } else { return(Request.CreateResponse(HttpStatusCode.BadRequest, "Sorry. You have no rights to add new journal voucher line in this journal voucher detail page.")); } } else { return(Request.CreateResponse(HttpStatusCode.BadRequest, "Sorry. You have no access in this journal voucher detail page.")); } } else { return(Request.CreateResponse(HttpStatusCode.BadRequest, "Theres no current user logged in.")); } } catch (Exception e) { Debug.WriteLine(e); return(Request.CreateResponse(HttpStatusCode.InternalServerError, "Something's went wrong from the server.")); } }