public virtual async Task <HttpResponseMessage> DeleteTransfer([FromBody] int id) { TransferMoneyRule transferMoneyRule = new TransferMoneyRule(); var resualt = await Rule.FindAsync(id); await Rule.DeleteAsync(id); await Rule.SaveChangesAsync(); return(Request.CreateResponse(HttpStatusCode.OK, new { resultCode = (int)ZhivarEnums.ResultCode.Successful, data = resualt })); }
public virtual async Task <HttpResponseMessage> GetTransferList() { try { var organId = Convert.ToInt32(SecurityManager.CurrentUserContext.OrganizationId); TransferMoneyRule transferMoneyRule = new TransferMoneyRule(); var resualt = await transferMoneyRule.GetAllByOrganIdAsync(organId); return(Request.CreateResponse(HttpStatusCode.OK, new { resultCode = (int)ZhivarEnums.ResultCode.Successful, data = resualt })); } catch (Exception ex) { throw; } }
public virtual async Task <HttpResponseMessage> GetLoadTransfer([FromBody] int id) { LoadTransfer loadTransfer = new LoadTransfer(); TransferMoneyRule transferMoneyRule = new TransferMoneyRule(); if (id > 0) { var transfer = await transferMoneyRule.GetByDocIdAsync(id); // int fromId, toId = 0; // if (transfer.From == "cash") // { // var cashFrom = await cashRule.GetByAccountId(Convert.ToInt32(transfer.FromDetailAccountId)); // fromId = cashFrom.ID; // if (transfer.To == "cash") // { // var cashTo = await cashRule.GetByAccountId(transfer.ToDetailAccountId); // toId = cashTo.ID; // } // else // { // var bankTo = await bankRule.GetByAccountId(transfer.ToDetailAccountId); // toId = bankTo.ID; // } // } // else // { // var bankFrom = await bankRule.GetByAccountId(Convert.ToInt32(transfer.FromDetailAccountId)); // fromId = bankFrom.ID; // if (transfer.To == "cash") // { // var cashTo = await cashRule.GetByAccountId(transfer.ToDetailAccountId); // toId = cashTo.ID; // } // else // { // var bankTo = await bankRule.GetByAccountId(transfer.ToDetailAccountId); // toId = bankTo.ID; // } // } loadTransfer = new LoadTransfer() { Amount = transfer.Amount, Date = transfer.Date, DisplayDate = transfer.DisplayDate, Description = transfer.Description, DocumentId = (int)transfer.DocumentId, DocumentNumber = transfer.DocumentNumber, From = transfer.From, FromDetailAccountId = Convert.ToInt32(transfer.FromDetailAccountId), FromDetailAccountName = transfer.FromDetailAccountName, FromReference = transfer.FromReference, To = transfer.To, ToDetailAccountId = Convert.ToInt32(transfer.ToDetailAccountId),// toId, ToDetailAccountName = transfer.ToDetailAccountName, ToReference = transfer.ToReference, }; return(Request.CreateResponse(HttpStatusCode.OK, new { resultCode = (int)ZhivarEnums.ResultCode.Successful, data = loadTransfer })); } loadTransfer = new LoadTransfer() { Amount = 0, Date = null, Description = "", DocumentId = 0, DocumentNumber = 0, From = null, FromDetailAccountId = 0, FromDetailAccountName = null, FromReference = "", To = null, ToDetailAccountId = 0, ToDetailAccountName = null, ToReference = "", }; return(Request.CreateResponse(HttpStatusCode.OK, new { resultCode = (int)ZhivarEnums.ResultCode.Successful, data = loadTransfer })); }
public virtual async Task <HttpResponseMessage> SaveTransfer([FromBody] TransferMoneyVM transferMoneyVM) { var organId = Convert.ToInt32(SecurityManager.CurrentUserContext.OrganizationId); if (!string.IsNullOrEmpty(transferMoneyVM.DisplayDate)) { var str = transferMoneyVM.DisplayDate.Replace("۰", "0").Replace("۱", "1").Replace("۲", "2").Replace("۳", "3").Replace("۴", "4").Replace("۵", "5").Replace("۶", "6").Replace("۷", "7").Replace("۸", "8").Replace("۹", "9"); transferMoneyVM.Date = PersianDateUtils.ToDateTime(str); } else { transferMoneyVM.Date = DateTime.Now; } if (!ModelState.IsValid) { return(Request.CreateResponse(HttpStatusCode.OK, new { resultCode = (int)ZhivarEnums.ResultCode.ValidationError, data = "" })); } var transferMoney = new TransferMoney(); Mapper.Map(transferMoneyVM, transferMoney); transferMoney.OrganId = organId; var fromName = string.Empty; var toName = string.Empty; AccountRule accountRule = new AccountRule(); if (transferMoneyVM.From == "bank") { var bankFrom = await accountRule.FindAsync(Convert.ToInt32(transferMoneyVM.FromDetailAccountId)); fromName = bankFrom.Name; } else { var cashFrom = await accountRule.FindAsync(Convert.ToInt32(transferMoneyVM.FromDetailAccountId)); fromName = cashFrom.Name; } if (transferMoneyVM.To == "bank") { var bankTo = await accountRule.FindAsync(Convert.ToInt32(transferMoneyVM.ToDetailAccountId)); toName = bankTo.Name; } else { var cashTo = await accountRule.FindAsync(Convert.ToInt32(transferMoneyVM.ToDetailAccountId)); toName = cashTo.Name; } transferMoney.Document = await createDocument(transferMoney, fromName, toName, organId); TransferMoneyRule transferMoneyRule = new TransferMoneyRule(); if (transferMoney.DocumentId != null && transferMoney.DocumentId > 0) { var oldTransfer = await transferMoneyRule.GetByDocIdAsync((int)transferMoney.DocumentId); //transferMoneyVM.ID = oldTransfer.ID; //transferMoney.ID = oldTransfer.ID; //transferMoney.Document.ID = oldTransfer.Document.ID; //transferMoney.DocumentId = oldTransfer.DocumentId; //transferMoney.Document.Transactions[0].ID = oldTransfer.Document.Transactions[0].ID; //transferMoney.Document.Transactions[1].ID = oldTransfer.Document.Transactions[1].ID; //transferMoney.Document.Transactions[0].DocumentId = oldTransfer.Document.ID; //transferMoney.Document.Transactions[1].DocumentId = oldTransfer.Document.ID; transferMoneyRule.Delete(oldTransfer.ID); await transferMoneyRule.SaveChangesAsync(); } //if (transferMoneyVM.ID.HasValue) //{ // transferMoneyRule.Update(transferMoney); //} //else //{ // transferMoneyRule.Insert(transferMoney); //} transferMoneyRule.Insert(transferMoney); await transferMoneyRule.SaveChangesAsync(); string result = transferMoneyVM.Amount + "," + fromName + "," + toName; return(Request.CreateResponse(HttpStatusCode.OK, new { resultCode = (int)ZhivarEnums.ResultCode.Successful, data = result })); }