public async Task <ActionResult> SetActive(Guid?userId) { int statusCode; string message; ExpoUser findedExpoUser = _db.GetCollection <ExpoUser>("ExpoUser").FindById(userId); if (findedExpoUser == null) { return(HttpNotFound()); } if (findedExpoUser.DateOfVisiting != null) { statusCode = 1; message = "Вы уже прибыли на выставку"; } else { string subject = "Спасибо за посещение"; string msg = $"Уважаемый(ая){findedExpoUser.UserName}\n Спасибо за то , что посетили нашу выставку"; string fromName = "Поддержка по отправке сообщение"; findedExpoUser.DateOfVisiting = DateTime.Now; string mailMessage = await findedExpoUser.SendMessageAsync(subject, msg, fromName); _db.GetCollection <ExpoUser>("ExpoUser").Update(userId, findedExpoUser); statusCode = 0; message = "Вы были активированы. " + mailMessage; } return(RedirectToAction("UserInfo", "User", new { statusCode, message })); }
public async Task <ActionResult> RegisterForm(ExpoUser expoUser) { int statusCode; string message; if (ModelState.IsValid) { using (_db) { try { string path; LiteCollection <ExpoUser> liteCollection = _db.GetCollection <ExpoUser>("ExpoUser"); ExpoUser findedExpoUser = liteCollection.FindOne(f => f.UserName == expoUser.UserName && f.UserEmail == expoUser.UserEmail && f.UserPhoneNumber == expoUser.UserPhoneNumber); if (findedExpoUser != null) { path = Server.MapPath("/Template/barcode-" + findedExpoUser.Id + ".gif"); if (!System.IO.File.Exists(path)) { liteCollection.Delete(findedExpoUser.Id); } else { await findedExpoUser.SendMessageAsync(path); return(RedirectToAction("UserRegistrationInfo", "User", new { expoUserId = findedExpoUser.Id })); } } Guid userIdGuid = Guid.NewGuid(); expoUser.Id = userIdGuid; expoUser.DateOfRegistration = DateTime.Now; expoUser.DateOfVisiting = null; Barcode128 code2 = new Barcode128 { CodeType = Barcode.CODE128_UCC, ChecksumText = true, GenerateChecksum = true, StartStopText = true, Code = userIdGuid.ToString() }; System.Drawing.Bitmap bm2 = new System.Drawing.Bitmap(code2.CreateDrawingImage(System.Drawing.Color.Black, System.Drawing.Color.White)); path = Server.MapPath("/Template/barcode-" + expoUser.Id + ".gif"); bm2.Save(path, System.Drawing.Imaging.ImageFormat.Gif); liteCollection.Insert(expoUser); liteCollection.EnsureIndex(e => e.Id); await expoUser.SendMessageAsync(path); return(RedirectToAction("UserRegistrationInfo", "User", new { expoUserId = expoUser.Id })); } catch (Exception e) { statusCode = 2; message = e.ToString(); } } } else { statusCode = 1; message = "Данные пришли пустыми"; } return(RedirectToAction("Register", "User", new { statusCode, message })); }