public IActionResult CheckSpinnerToDisplay(int?userId) { var checkUser = new SpinUserData(); var Spinnoptions = db.SpinnerPromotion.Where(x => x.IsActive == true && x.ActiveTo.Value.Date >= DateTime.Now.Date && x.ActiveFrom.Value.Date <= DateTime.Now.Date).ToList(); if (userId > 0) { checkUser = db.SpinUserData.Where(x => x.UserId == userId).FirstOrDefault(); } else { if (Spinnoptions.Count > 0) { return(Ok(true)); } else { return(Ok(false)); } } if (checkUser != null) { var date = DateTime.Now.AddHours(-24); if (checkUser.CancelCounter >= 3 && checkUser.CancelDate > date) { return(Ok(false)); } else if (checkUser.CancelCounter >= 3 && checkUser.CancelDate.Value <= date && Spinnoptions.Count > 0) { checkUser.CancelCounter = 0; checkUser.CancelDate = DateTime.Now; db.SaveChanges(); return(Ok(true)); } else { if (Spinnoptions.Count > 0) { return(Ok(true)); } else { return(Ok(false)); } } } else { if (Spinnoptions.Count > 0) { return(Ok(true)); } else { return(Ok(false)); } } }
public IActionResult cancelCounterCheck(int userId, int cancelClick) { var counter = 1; var checkUser = new SpinUserData(); try { if (userId > 0) { checkUser = db.SpinUserData.Where(x => x.UserId == userId).FirstOrDefault(); if (checkUser != null) { if (cancelClick > 0) { var count = ++checkUser.CancelCounter ?? 1; checkUser.CancelCounter = count; checkUser.CancelDate = DateTime.Now; checkUser.SpinCount = 0; db.SaveChanges(); } counter = checkUser.CancelCounter ?? 1; } else { var model = new SpinUserData(); model.CancelCounter = 1; model.IsActive = true; model.IsUsed = false; model.CancelDate = DateTime.Now; model.UserId = userId; db.SpinUserData.Add(model); db.SaveChanges(); } } return(Ok(counter)); } catch (Exception ex) { throw ex; } }
public async Task <IActionResult> saveDataAsync([FromBody] spin model) { try { if (model != null) { if (model.UserId > 0) { var UserSpindata = db.SpinUserData.Where(x => x.UserId == model.UserId).FirstOrDefault(); if (UserSpindata == null) { var data = new SpinUserData(); data.IsActive = true; data.SpinCount = model.SpinCount; data.SpinnerPromotionId = model.SpinnerPromotionId; data.UserId = model.UserId; data.MoodId = model.MoodId; data.IsUsed = false; var date = Convert.ToDateTime(DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss")); data.SpinDate = date; data.CancelCounter = 0; db.SpinUserData.Add(data); db.SaveChanges(); } else { UserSpindata.IsActive = true; UserSpindata.SpinCount = model.SpinCount; UserSpindata.SpinnerPromotionId = model.SpinnerPromotionId; UserSpindata.UserId = model.UserId; UserSpindata.MoodId = model.MoodId; UserSpindata.IsUsed = false; UserSpindata.CancelCounter = 0; var date = Convert.ToDateTime(DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss")); UserSpindata.SpinDate = date; db.SaveChanges(); } if (model.MoodId == 3) { if (model.SpinnerPromotionId > 0) { var userEmail = db.Users.Where(x => x.Id == model.UserId).FirstOrDefault(); var spinnerdata = db.SpinnerPromotion.Where(x => x.Id == model.SpinnerPromotionId).FirstOrDefault(); var url = ""; if (spinnerdata.CategoryId > 0) { url = "https://www.pistis.com.mx/productcatalogue?Id=" + spinnerdata.CategoryId; if (spinnerdata.ProductCategoryId > 0) { url = "https://www.pistis.com.mx/productcatalogue?Id=" + spinnerdata.ProductCategoryId; if (spinnerdata.ProductId > 0)//productvarientId { var productId = db.ProductVariantDetails.Where(x => x.Id == spinnerdata.ProductId).FirstOrDefault(); url = "https://www.pistis.com.mx/product-details?Id=" + productId.ProductId + "&variantId=" + productId.Id; } } } var html = System.IO.File.ReadAllText(environment.WebRootPath + "/Template/Spinner.html"); html = html.Replace("{{url}}", url); html = html.Replace("{{Prizename}}", spinnerdata.Description); Emailmodel emailmodel = new Emailmodel(); emailmodel.From = ""; emailmodel.To = userEmail?.Email; emailmodel.Subject = "!Felicidades! Has recibido un cupon PISTIS Mexico."; // emailmodel.Body = "Mail Subject : Your order from PISTIS.com.mx of" + productName + "Hi " + sendingdetails.UserName + "Thanks for your order. Your request will be reviewed against availability of inventory, if confirmed you will receive an email with more details. Additional information .The details of your order are indicated below. Your esitmated delivary date is:"+ deliveryDate + "Shipping Type:"+ sendingdetails.shippingType; emailmodel.Body = html; emailmodel.key = "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"; await Example.Execute(emailmodel); } } } } else { var data = new SpinUserData(); data.IsActive = true; data.SpinCount = model.SpinCount; data.SpinnerPromotionId = model.SpinnerPromotionId; data.UserId = model.UserId; data.CancelCounter = 0; db.SpinUserData.Add(data); db.SaveChanges(); } } catch (Exception ex) { return(Ok(ex)); } return(Ok()); }