public async Task <IHttpActionResult> UpdateCase(UserCasesViewModel model) { if (model.Refund != 0) { return(Ok(await Refund(model))); } else { return(Ok(await Charges(model))); } }
public async Task <ObjectDto <string> > Refund(UserCasesViewModel model) { var messages = new Messages(); ObjectDto <string> result = new ObjectDto <string>(); using (var db = new ApplicationDbContext()) { var userCaseDto = await db.UserCases.FindAsync(model.Id); var userId = User.Identity.GetUserId(); var userObj = await db.PUserProfile.FindAsync(userId); var childObj = await db.PUserProfile.FindAsync(userCaseDto.UserId); if (userObj.Balance >= model.Refund) { userObj.Balance -= model.Refund; childObj.Balance += model.Refund; userCaseDto.LastModifiedDate = TimeZoneInfo.ConvertTime(DateTime.Now, TimeZoneInfo.FindSystemTimeZoneById("India Standard Time")); childObj.LastModifiedDate = TimeZoneInfo.ConvertTime(DateTime.Now, TimeZoneInfo.FindSystemTimeZoneById("India Standard Time")); userObj.LastModifiedDate = TimeZoneInfo.ConvertTime(DateTime.Now, TimeZoneInfo.FindSystemTimeZoneById("India Standard Time")); userCaseDto.Status = (int)UserCasesStatus.Closed; userCaseDto.Remarks += "<br/>Admin:" + model.Remarks; userCaseDto.Refund = model.Refund; db.Entry(userCaseDto).State = EntityState.Modified; db.Entry(userObj).State = EntityState.Modified; db.Entry(childObj).State = EntityState.Modified; var childPassBook = new PassBookDto { Amount = model.Refund, Balance = childObj.Balance, Credit = model.Refund, Debit = 0, ServiceId = userCaseDto.ServiceTypeId, Status = (int)StatusFlag.Success, TransactionId = model.TransactionId, UserId = childObj.UserId, Remarks = ((UserCaseReason)userCaseDto.Issue).ToString().Replace("_", " ") + " Refund", LastModifiedDate = TimeZoneInfo.ConvertTime(DateTime.Now, TimeZoneInfo.FindSystemTimeZoneById("India Standard Time")), CreatedDate = TimeZoneInfo.ConvertTime(DateTime.Now, TimeZoneInfo.FindSystemTimeZoneById("India Standard Time")) }; var userPassBook = new PassBookDto { Amount = model.Refund, Balance = userObj.Balance, Credit = 0, Debit = model.Refund, Status = (int)StatusFlag.Success, TransactionId = model.TransactionId, UserId = userObj.UserId, Remarks = ((UserCaseReason)userCaseDto.Issue).ToString().Replace("_", " ") + " Refund", ServiceId = userCaseDto.ServiceTypeId, LastModifiedDate = TimeZoneInfo.ConvertTime(DateTime.Now, TimeZoneInfo.FindSystemTimeZoneById("India Standard Time")), CreatedDate = TimeZoneInfo.ConvertTime(DateTime.Now, TimeZoneInfo.FindSystemTimeZoneById("India Standard Time")) }; db.PassBook.Add(userPassBook); db.PassBook.Add(childPassBook); if ((await db.SaveChangesAsync()) > 0) { result.valid = true; messages.Message = "Case closed & amount has been refunded to " + model.Agency + "'s account"; messages.Type = Toaster.SUCCESS.ToString(); result.messages.Add(messages); } else { messages.Message = "Internal Server Error."; result.messages.Add(messages); } } else { messages.Message = "Not enough balance is available in your account"; result.messages.Add(messages); } } return(result); }