public string GenerateDobiToken(DobiBasicInformation dobi) { try { var issuer = WebConfigurationManager.AppSettings["issuer"]; var audience = WebConfigurationManager.AppSettings["aud"]; var key = WebConfigurationManager.AppSettings["secret"]; var identity = new ClaimsIdentity("JWT"); identity.AddClaim(new Claim("dobiId", dobi.DobiId)); identity.AddClaim(new Claim("name", dobi.Name)); identity.AddClaim(new Claim("phone", dobi.Phone)); identity.AddClaim(new Claim("photo", dobi.Photo ?? "")); identity.AddClaim(new Claim(ClaimTypes.Role, "dobi")); var now = DateTime.UtcNow; var expires = now.AddDays(Validity); var symmetricKeyAsBase64 = key; var keyByteArray = TextEncodings.Base64Url.Decode(symmetricKeyAsBase64); var signingKey = new HmacSigningCredentials(keyByteArray); var token = new JwtSecurityToken(issuer, audience, identity.Claims, now, expires, signingKey); var handler = new JwtSecurityTokenHandler(); var jwtToken = handler.WriteToken(token); return(jwtToken); } catch (Exception e) { throw; } }
public async Task <bool> SetOrderPickupDateTime(OrderPickupTimeViewModel order, DobiBasicInformation dobi) { try { var orderPickupDate = Utilities.GetMillisecondFromDate(order.PickupDate); var result = await _orderRepository.SetOrderPickupDateTime(orderPickupDate, order.PickupTime, order.ServiceId, dobi); if (result == null) { return(false); } var messageSend = await _userMessageBusiness.AddUserMessage(result.OrderBy.UserId, (int)MessageType.OrderAcknowledge, result.ServiceId); if (messageSend == null) { return(false); } var notification = new Notification { Type = (int)NotificationType.SetOrderPickupTime, MessageId = messageSend, Title = Constants.ACK_MESSAGE_TITLE, Text = string.Format(Constants.ACK_MESSAGE_TEXT, order.ServiceId), SenderUserName = dobi.Name, SenderUserId = dobi.DobiId, ReceiverUserName = result.OrderBy.Name, ReceiverUserId = result.OrderBy.UserId, Status = (int)NotificationStatus.NotSent, NotificationId = Guid.NewGuid().ToString() }; var notificationAdd = await _notificationRepository.AddNotification(notification); return(notificationAdd); } catch (Exception ex) { throw new Exception("Error setting pickup date time" + ex); } }
public async Task <Order> SetOrderPickupDateTime(long date, string time, string serviceId, DobiBasicInformation dobi) { try { var filter = Builders <Order> .Filter.Eq(d => d.ServiceId, serviceId); var update = Builders <Order> .Update.Set(u => u.Status, (int)OrderStatus.Acknowledged) .Set(u => u.PickUpDate, date) .Set(u => u.PickUpTime, time) .Set(u => u.Dobi, dobi); var projection = Builders <Order> .Projection.Exclude("_id"); var options = new FindOneAndUpdateOptions <Order, Order>(); options.ReturnDocument = ReturnDocument.After; options.Projection = projection; var result = await Collection.FindOneAndUpdateAsync(filter, update, options); return(result); } catch (Exception ex) { throw new Exception("Error setting pickup date time"); } }