public async Task <IActionResult> ConfiermSealler(SeallerCodeConfiermModelView model) { var user = await userManager.FindByIdAsync(User.FindFirst("Id")?.Value); if (!await userManager.IsInRoleAsync(user, "Adman") && user.Block) { return(Unauthorized()); } var Sealler = await userManager.FindByIdAsync(model.SeallerId); if (Sealler == null) { return(NotFound()); } if (await userManager.IsInRoleAsync(Sealler, "Sealler")) { if (model.Confierm) { Sealler.Confirmed = Confirmed.approved; } else { Sealler.Confirmed = Confirmed.Reject; } await userManager.UpdateAsync(Sealler); var SellerName = _contect.Seallers.SingleOrDefault(i => i.id == Sealler.Id); var Body = AlertNotifiction.ReadeFile("wwwroot//Emailfile//conformseller.html") .Replace("#name#", SellerName.projectAName); AlertNotifiction.SendEmail(user.Email, " Conform Account", _SmtpSettings, Body); //AlertNotifiction.SendEmail(Sealler.Email, " Conform Account", _SmtpSettings, $"Dear {Sealler.UserName } <br> Acount is " + Sealler.Confirmed.ToString()); return(Ok(new { Sealler.Id })); } else { return(NotFound()); } }
// [Obsolete] public async Task <IActionResult> GetConformUser(string Email) { var user = await userManager.FindByNameAsync(Email); if (await userManager.IsInRoleAsync(user, "User") && user.Confirmed != Confirmed.block && !user.Block) { var Code = new Random().Next(1234, 9999); var UserCode = _contect.UserCodeConfierm.SingleOrDefault(i => i.UserId == user.Id && i.Type == Codetype.PasswordUser); if (UserCode != null) { UserCode.Code = Code.ToString(); UserCode.ExperdDate = DateTime.Now.AddMinutes(10); UserCode.Type = Codetype.PasswordUser; } else { var UserCodeConfierm = new UserCodeConfierm() { ExperdDate = DateTime.Now.AddMinutes(10), UserId = user.Id, Code = Code.ToString(), Type = Codetype.PasswordUser }; _contect.UserCodeConfierm.Add(UserCodeConfierm); } _contect.SaveChanges(); var Use = _contect.Users.SingleOrDefault(i => i.id == user.Id); var Body = AlertNotifiction.ReadeFile("wwwroot//Emailfile//conformEmile.html") .Replace("#name#", Use.AName).Replace("#code#", Code.ToString()); AlertNotifiction.SendEmail(user.Email, " Conform Account", _SmtpSettings, Body); return(Ok()); } else { return(NotFound()); } }
public async Task <IActionResult> Approved(orderstateModeview model) { try { var user = await userManager.FindByIdAsync(User.FindFirst("Id")?.Value); if (user == null) { return(Unauthorized()); } if (await userManager.IsInRoleAsync(user, "Sealler") && user?.Confirmed == Confirmed.approved && !user.Block) { var order = _contect.Orders.Include(i => i.User.UserIdentity).SingleOrDefault(i => i.Id == model.OrderId && i.SeallerId == user.Id); if (order == null) { return(NotFound()); } //get UserDevice Key var connectionFierbaseId = _contect.NotificationTokens.Where(i => i.UserId == order.UserId).Select(i => i.connectionFierbaseId).ToList(); if (order.Cancel) { return(BadRequest($"order Cancel from User")); } if (model.orderStatus == orderStatus.Approved) { if (order.orderStatus == orderStatus.Reject || order.orderStatus == orderStatus.Ordered) { order.orderStatus = model.orderStatus; AlertNotifiction.Notifiction_push(ServerKey, senderId, connectionFierbaseId, " قبول الطلب ", $"{order.ProductAName} تم قبول طلب للمنتج "); } else { throw new Exception($"order is {order.orderStatus} "); } } else if (model.orderStatus == orderStatus.Reject) { if (order.orderStatus == orderStatus.Ordered || order.orderStatus == orderStatus.Approved) { order.orderStatus = model.orderStatus; AlertNotifiction.Notifiction_push(ServerKey, senderId, connectionFierbaseId, " رفض الطلب ", $"{order.ProductAName} تم رفض طلب للمنتج "); } else { throw new Exception($"order is {order.orderStatus} "); } } else if (model.orderStatus == orderStatus.Finshed) { if (order.orderStatus == orderStatus.Approved) { order.orderStatus = model.orderStatus; AlertNotifiction.Notifiction_push(ServerKey, senderId, connectionFierbaseId, " الطلب ", $"{order.ProductAName} تم قبول طلب للمنتج "); } else { throw new Exception($"order is {order.orderStatus} "); } } else if (model.orderStatus == orderStatus.delivery) { if (order.orderStatus == orderStatus.Finshed || order.orderStatus == orderStatus.Approved) { order.orderStatus = model.orderStatus; AlertNotifiction.Notifiction_push(ServerKey, senderId, connectionFierbaseId, " طلب ", $"{order.ProductAName} خلال 24 ساعة طلبك في الوصول اليك "); var Body = AlertNotifiction.ReadeFile("wwwroot//Emailfile//OrderDelvery.html") .Replace("#name#", order.User.Name) .Replace("#oductName#", order.ProductAName) ; AlertNotifiction.SendEmail(order.User.UserIdentity.Email, "orderStatus delivery", _SmtpSettings, Body); // #oductName# string body = $"Hi \n the Receipt Code of Order Number# :{order.Id.ToString()} \n Receipt Code : {ReceiptCode.Code.ToString()} \n ExperDate : { ReceiptCode.ExperDate.ToString()}"; // AlertNotifiction.SendEmail(order.User.UserIdentity.Email, "orderStatus delivery", _SmtpSettings, $"Hi {order.User.Name} <br> order is delivery <br> order Number #{order.Id} thx :) "); } else { throw new Exception($"order is {order.orderStatus} "); } } else { throw new Exception($"order is {order.orderStatus} "); } _contect.SaveChanges(); return(Ok( new { order.Id, order.ProductName, order.ProductAName, order.Productprice, order.description, // ProductForm = order.Form.Select(i => new { i.id, i.AKey, i.Key, i.value }).ToList(), order.CodeColor, order.ANameColor, order.NameColor, order.orderStatus, order.Cuantity, order.ProductpriceTotal, order.Date, order.Timespent, order.TimespentEnd, order.UserAddress, order.otherPhoneNo, })); } else if (await userManager.IsInRoleAsync(user, "Adman") && user?.Confirmed == Confirmed.approved && !user.Block) { var order = _contect.Orders.Include(i => i.User.UserIdentity).SingleOrDefault(i => i.Id == model.OrderId); if (order == null) { return(NotFound()); } if (model.orderStatus == orderStatus.Approved) { if (order.orderStatus == orderStatus.Reject || order.orderStatus == orderStatus.Ordered) { order.orderStatus = model.orderStatus; } else { throw new Exception($"order is {order.orderStatus} "); } } else if (model.orderStatus == orderStatus.Reject) { if (order.orderStatus == orderStatus.Ordered || order.orderStatus == orderStatus.Approved) { order.orderStatus = model.orderStatus; } else { throw new Exception($"order is {order.orderStatus} "); } } else if (model.orderStatus == orderStatus.Finshed) { if (order.orderStatus == orderStatus.Approved) { order.orderStatus = model.orderStatus; } else { throw new Exception($"order is {order.orderStatus} "); } } else if (model.orderStatus == orderStatus.delivery) { if (order.orderStatus == orderStatus.Finshed || order.orderStatus == orderStatus.Approved) { order.orderStatus = model.orderStatus; } else { throw new Exception($"order is {order.orderStatus} "); } } else if (model.orderStatus == orderStatus.Receipt) { if (order.orderStatus == orderStatus.Finshed || order.orderStatus == orderStatus.delivery) { order.orderStatus = model.orderStatus; try { // string body = $"Hi \n the Receipt Code of Order Number# :{order.Id.ToString()} \n Receipt Code : {ReceiptCode.Code.ToString()} \n ExperDate : { ReceiptCode.ExperDate.ToString()}"; AlertNotifiction.SendEmail(order.User.UserIdentity.Email, "orderStatus Receipt", _SmtpSettings, "Hi the Receipt Code of Receipt Code : "); } catch (Exception e) { } } else { throw new Exception($"order is {order.orderStatus} "); } } else { throw new Exception($"order is {order.orderStatus} "); } _contect.SaveChanges(); return(Ok( new { order.Id, order.ProductName, order.ProductAName, order.Productprice, order.description, // ProductForm = order.Form.Select(i => new { i.id, i.AKey, i.Key, i.value }).ToList(), order.CodeColor, order.ANameColor, order.NameColor, order.orderStatus, order.Cuantity, order.ProductpriceTotal, order.Date, order.Timespent, order.TimespentEnd, order.UserAddress, order.otherPhoneNo, })); } else { return(Unauthorized()); } } catch (Exception e) { return(BadRequest(e.Message)); } }
public async Task <IActionResult> RegisterUser(UserModelview model) { if (ModelState.IsValid) { var User = new UserIdentity() { UserName = model.Email, PhoneNumber = model.Phon, Email = model.Email, Confirmed = Confirmed.non, Block = false }; try { var result = await userManager.CreateAsync(User, model.Password); if (result.Succeeded) { var user = new User() { id = User.Id, Name = model.Name, AName = model.AName, Hdate = DateTime.Now, }; if (!await roleManager.RoleExistsAsync("User")) { await roleManager.CreateAsync(new IdentityRole("User")); } await userManager.AddToRoleAsync(User, "User"); _contect.Users.Add(user); _contect.SaveChanges(); //get Token :) var claim = new[] { new Claim("Id", User.Id), new Claim("Rolas", userManager.GetRolesAsync(User).Result.FirstOrDefault()) }; var signinKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(_configuration["Jwt:SigningKey"])); int expiryInMinutes = Convert.ToInt32(_configuration["Jwt:ExpiryInHouer"]); var token = new JwtSecurityToken( claims: claim, issuer: _configuration["Jwt:Site"], audience: _configuration["Jwt:Site"], expires: DateTime.UtcNow.AddHours(expiryInMinutes), signingCredentials: new SigningCredentials(signinKey, SecurityAlgorithms.HmacSha256) ); /// code conform var Code = new Random().Next(1234, 9999); var UserCodeConfierm = new UserCodeConfierm() { ExperdDate = DateTime.Now.AddMinutes(10), UserId = user.id, Code = Code.ToString(), Type = Codetype.PasswordUser }; _contect.UserCodeConfierm.Add(UserCodeConfierm); _contect.SaveChanges(); var Body = AlertNotifiction.ReadeFile("wwwroot//Emailfile//conformEmile.html") .Replace("#name#", user.AName).Replace("#code#", Code.ToString()); AlertNotifiction.SendEmail(user.UserIdentity.Email, " Conform Account", _SmtpSettings, Body); return(Ok(new { token = new JwtSecurityTokenHandler().WriteToken(token), expiration = token.ValidTo, user.id, user.Name, user.AName, user.UserIdentity.Email, user.UserIdentity.PhoneNumber, Roles = userManager.GetRolesAsync(User).Result.FirstOrDefault() })); } else { return(BadRequest()); } } catch (Exception e) { return(BadRequest(new IdentityError() { Description = e.Message.ToString() })); } } else { return(BadRequest()); } }