public IActionResult ChargePocket(long TechnicalId, double value) { try { var technical = _uow.UsersRepository.GetAll().Where(ent => ent.Id == TechnicalId).Include(ent => ent.Technical).FirstOrDefault(); if (technical == null || technical.Technical == null) { return(Ok(new ApiResponseModel { Status = EN_ResponseStatus.Faild, Message = "Technical with Id: " + TechnicalId + " not found", Data = null, Errors = new string[] { "Technical with Id: " + TechnicalId + " not found" } })); } else { //Update Technical Pocket Value technical.Technical.Pocket += value; technical.ModificationDate = DateTime.Now; _uow.UsersRepository.Update(technical); //Add to Pocket History PocketHistory pocketHistory = new PocketHistory(); pocketHistory.Value = value; pocketHistory.Transaction = (int)EN_Transactions.Charge; pocketHistory.ToUSer = TechnicalId; pocketHistory.TypeUser = (int)EN_TypeUser.Technical; pocketHistory.Text = "A new Value : " + value + " Added to Your Pocket "; _uow.PocketHistoryRepository.Add(pocketHistory); //Add notification to technical Notification notification = new Notification(); notification.Text = "A new Value : " + value + " Added to Your Pocket Successfully"; notification.ToUSer = TechnicalId; notification.TypeOfUser = (int)EN_TypeUser.Technical; _uow.NotificationRepository.Add(notification); _uow.Save(); return(Ok(new ApiResponseModel { Status = EN_ResponseStatus.Success, Message = "Record Updated Successfully", Data = null, Errors = null })); } } catch (Exception ex) { return(Ok(new ApiResponseModel { Status = EN_ResponseStatus.Faild, Message = "Error: " + ex.Message, Data = null, Errors = new string[] { "Error: " + ex.Message } })); } }
public IActionResult ChargePocket(long CustomerId, double value) { try { var customer = _uow.CustomerRepository.GetAll().Where(ent => ent.Id == CustomerId).FirstOrDefault(); if (customer == null) { return(Ok(new ApiResponseModel { Status = EN_ResponseStatus.Faild, Message = "Customer With Id: " + CustomerId + " not found", Data = null, Errors = new string[] { "Customer with Id: " + CustomerId + " not found" } })); } else { //Update Customer Pocket Value customer.Pocket += value; customer.ModificationDate = DateTime.Now; _uow.CustomerRepository.Update(customer); //Add to Pocket History PocketHistory pocketHistory = new PocketHistory(); pocketHistory.Value = value; pocketHistory.Transaction = (int)EN_Transactions.Charge; pocketHistory.ToUSer = CustomerId; pocketHistory.TypeUser = (int)EN_TypeUser.Customer; pocketHistory.Text = "A new Value : " + value + " Added to Your Pocket "; _uow.PocketHistoryRepository.Add(pocketHistory); //Add notification to customer Notification notification = new Notification(); notification.Text = "A new Value : " + value + " Added to Your Pocket Successfully"; notification.ToUSer = CustomerId; notification.TypeOfUser = (int)EN_TypeUser.Customer; _uow.NotificationRepository.Add(notification); _uow.Save(); return(Ok(new ApiResponseModel { Status = EN_ResponseStatus.Success, Message = "Pocket Updated Successfully", Data = null, Errors = null })); } } catch (Exception ex) { return(Ok(new ApiResponseModel { Status = EN_ResponseStatus.Faild, Message = "Error: " + ex.Message, Data = null, Errors = new string[] { "Error: " + ex.Message } })); } }