public async Task <IActionResult> AssignRecordToDriver(RecordAssignInput input) { Record record = await _db.Records.FirstOrDefaultAsync(x => x.RecordGuid == input.RecordId); record.DriverId = input.DriverId; long userId = _db.Drivers.FirstOrDefault(y => y.Id == input.DriverId).UserId; _db.Entry(record).State = EntityState.Modified; var result = await _db.SaveChangesAsync(); if (result == 1) { PushNotificationInput pushNotificationInput = new PushNotificationInput { UserId = userId, title = "كشف جديد", body = "تم تعيين كشف جديد لك", }; await _pushNotificationService.PushNotification(pushNotificationInput); return(new OkObjectResult(1)); } throw new Exception("حصل خطأ"); }
public async Task addClients() { List <ApplicationUser> applicationUsers = new List <ApplicationUser>(); List <Client> clients = _db.Clients.Where(x => !x.UserId.HasValue).ToList(); foreach (Client client in clients) { ApplicationUser user = new ApplicationUser { CreatedAt = DateTime.Now, CreatedBy = 10033, Email = "", FullName = client.ClientFullName, IsActive = client.IsActive, MobileNumber = GetUntilOrEmptyMobile(client.MobileNumber).Trim(), UserName = GetUntilOrEmpty(client.MobileNumber).Trim(), UserGuid = Guid.NewGuid(), }; var result = await _userManager.CreateAsync(user, "123456"); if (result.Succeeded) { CreateRoleIfNotExist("Client", user.Id); client.UserId = user.Id; _db.Entry(client).State = EntityState.Modified; _db.SaveChanges(); } else { applicationUsers.Add(user); } } }
public Area Update(AreaUpdate model) { Area area = new Area(); area.AreaName = model.AreaName; area.AreaGuid = model.AreaGuid; area.AreaGroupId = (int)model.AreaGroupId; area.CityId = (int)model.CityId; area.DriverPrice = (double)model.DriverPrice; area.Id = model.Id; _db.Entry(area).State = EntityState.Modified; _db.SaveChanges(); return(area); }
private bool BindRecordOrders(List <OrderResponseWithRevenue> orders, int recordId) { if (orders.Count() > 0) { foreach (var order in orders) { Order order1 = _db.Orders.FirstOrDefault(x => x.Id == order.Id); order1.RecordId = recordId; _db.Entry(order1).State = EntityState.Modified; _db.SaveChanges(); } return(true); } return(true); }
public Order Update(OrderUpdate model) { Order order = _db.Orders .Include(c => c.Record) .Include(c => c.Client) .Include(a => a.Area) .ThenInclude(a => a.AreaGroup) .Where(x => x.Id == model.Id).FirstOrDefault(); long userId = _principalService.GetUserId(); order.Address = model.Address; order.AreaId = model.AreaId; order.ClientId = model.ClientId; order.ClientStatus = model.ClientStatus; order.DeliveryPhoneNumber = model.DeliveryNumber; order.OrderItemTypeDescription = model.OrderItemDescription; order.OrderStatusId = model.OrderStatusId; order.OrderTotalPrice = model.OrderTotalPrice; order.PolicyNumber = model.PolicyNumber; order.OrderDate = model.OrderDate; order.AddedPrice = model.AddedPrice; CalculateRevenueForOrder(order); Record record = _db.Records.FirstOrDefault(x => x.AreaGroupId == order.Area.AreaGroupId && x.RecordDate == model.OrderDate); if (record != null) { order.RecordId = record.Id; } else { Record newRecord = new Record { AreaGroupId = order.Area.AreaGroupId, CreatedAt = DateTime.Now, CreatedById = userId, RecordDate = order.OrderDate, RecordGuid = Guid.NewGuid(), IsActive = true }; _db.Records.Add(newRecord); _db.SaveChanges(); order.RecordId = newRecord.Id; } _db.Entry(order).State = EntityState.Modified; _db.SaveChanges(); if (order.OrderStatusId == (int)OrderStatusEnum.Completed) { PushNotificationInput pushNotificationInput = new PushNotificationInput(); pushNotificationInput.UserId = order.Client.UserId; pushNotificationInput.title = "تم توصيل طلبك "; pushNotificationInput.body = "تم توصيل طلبك بنجاح"; pushNotificationInput.data = new { orderId = order.Id }; _pushNotificationService.PushNotification(pushNotificationInput); } return(order); }