public JsonResult ForGotPassword(string email, string idcard) { try { if (!email.IsEmailFormat()) { return(Json(new { status = false, message = "Email or ID Card Number incorrect!" }, JsonRequestBehavior.AllowGet)); } var item = _dbContext.UserAccounts.FirstOrDefault(x => x.Email == email && x.IDcardNumber == idcard); if (item != null) { var password = CodeUtility.RandomString(3); string from = ConfigurationManager.AppSettings["FromEmailAddress"].ToSafetyString(); string host = ConfigurationManager.AppSettings["Host"].ToSafetyString(); string content = "[KPI System] Your password is '<strong style='color:red'>" + password + "</strong>' . Please you login with this password and change the password. Link: " + host; string to = email.ToSafetyString(); string subject = "Reset password"; item.Password = password.SHA256Hash(); _dbContext.SaveChanges(); if (Commons.SendMail(from, to, subject, content)) { return(Json(new { status = true, message = "A new password has already sent to your company email!" }, JsonRequestBehavior.AllowGet)); } else { return(Json(new { status = false, message = "Send mail failed!" }, JsonRequestBehavior.AllowGet)); } } else { return(Json(new { message = "Email or ID Card Number incorrect!" }, JsonRequestBehavior.AllowGet)); } } catch (Exception) { return(Json(new { status = false, message = "Error!" }, JsonRequestBehavior.AllowGet)); } }
private async Task <string> GenatateGlueCode(string code) { int lenght = 8; if (await _repoGlue.FindAll().AnyAsync(x => x.Code.Equals(code)) == true) { var newCode = CodeUtility.RandomString(lenght); return(await GenatateGlueCode(newCode)); } return(code); }
public async Task <MixingInfo> Mixing(MixingInfoForCreateDto mixing) { var item = _mapper.Map <MixingInfoForCreateDto, MixingInfo>(mixing); item.Code = CodeUtility.RandomString(8); item.CreatedTime = DateTime.Now; var glue = _repoGlue.FindById(mixing.GlueID); item.ExpiredTime = DateTime.Now.AddMinutes(glue.ExpiredTime); _repoMixingInfor.Add(item); await _repoMixingInfor.SaveAll(); return(item); }
public async Task <bool> ReceiveRegister(List <ReceiveDetailModel> data, string userId) { // Thêm vào bảng Receive var receiveID = CodeUtility.RandomString(); var receiveModel = new Receive_Dto(); receiveModel.ID = receiveID; receiveModel.UserID = userId; receiveModel.Register_Date = DateTime.Now; receiveModel.Updated_Time = DateTime.Now; receiveModel.Status = "0"; var user = await _serverUser.GetUserById(userId); receiveModel.DepID = user.DepID; var receive = _mapper.Map <Receive>(receiveModel); _repoReceive.Add(receive); // Thêm vào bảng Receive Detail foreach (var item in data) { var receiveDetail = new Receive_Detail(); receiveDetail.CatID = item.CatID; receiveDetail.CatName = item.CatName; receiveDetail.ReceiveID = receive.ID; receiveDetail.ProductID = item.ProductID; receiveDetail.ProductName = item.ProductName; receiveDetail.Qty = item.Qty; receiveDetail.Update_Time = DateTime.Now; _repoReceiveDetail.Add(receiveDetail); } try { return(await _repoReceiveDetail.SaveAll()); } catch (System.Exception ex) { throw ex; } }
public async Task <MixingInfo> Mixing(MixingInfoForCreateDto mixing) { try { var item = _mapper.Map <MixingInfoForCreateDto, MixingInfo>(mixing); item.Code = CodeUtility.RandomString(8); item.CreatedTime = DateTime.Now; var glue = await _repoGlue.FindAll().FirstOrDefaultAsync(x => x.isShow == true && x.ID == mixing.GlueID); item.ExpiredTime = DateTime.Now.AddMinutes(glue.ExpiredTime); _repoMixingInfor.Add(item); await _repoMixingInfor.SaveAll(); // await _repoMixing.AddOrUpdate(item.ID); return(item); } catch { return(new MixingInfo()); } }