public async Task <IActionResult> Create(RequestProductBanner productBanner) { if (productBanner.file != null) { var savePath = Path.Combine(Directory.GetCurrentDirectory(), @"wwwroot\Upload", productBanner.file.FileName); using (var stream = new FileStream(savePath, FileMode.Create)) { await productBanner.file.CopyToAsync(stream); } productBanner.ImgUrl = "/Upload/" + productBanner.file.FileName; } try { var targer = new ProductBanners() { ImgUrl = productBanner.ImgUrl, PublishDate = productBanner.PublishDate, Url = productBanner.Url, DownDate = productBanner.DownDate, Title = productBanner.Title }; _context.ProductBanners.Add(targer); await _context.SaveChangesAsync(); return(Ok()); } catch (Exception ex) { return(StatusCode(Status400BadRequest, new ResponseMessage { Message = "查無資訊" })); } }
public async Task <IActionResult> Create(RequestKeyVisuals keyVisual) { if (keyVisual.file != null) { var savePath = Path.Combine(Directory.GetCurrentDirectory(), @"wwwroot\Upload", keyVisual.file.FileName); using (var stream = new FileStream(savePath, FileMode.Create)) { await keyVisual.file.CopyToAsync(stream); } keyVisual.ImgUrl = "/Upload/" + keyVisual.file.FileName; } try { var target = new KeyVisuals() { DownDate = keyVisual.DownDate, PublishDate = keyVisual.PublishDate, Url = keyVisual.Url, ImgUrl = keyVisual.ImgUrl, Title = keyVisual.Title }; _context.KeyVisuals.Add(target); await _context.SaveChangesAsync(); return(Ok()); } catch (Exception ex) { return(StatusCode(Status400BadRequest, new ResponseMessage { Message = "查無資訊" })); } }
public async Task <IActionResult> Create(RequestSeasonalActivities seasonalActivity) { if (seasonalActivity.file != null) { var savePath = Path.Combine(Directory.GetCurrentDirectory(), @"wwwroot\Upload", seasonalActivity.file.FileName); using (var stream = new FileStream(savePath, FileMode.Create)) { await seasonalActivity.file.CopyToAsync(stream); } seasonalActivity.ImgUrl = "/Upload/" + seasonalActivity.file.FileName; } try { var target = new SeasonalActivities() { Url = seasonalActivity.Url, ImgUrl = seasonalActivity.ImgUrl, DownDate = seasonalActivity.DownDate, PublishDate = seasonalActivity.PublishDate, Title = seasonalActivity.Title }; _context.SeasonalActivities.Add(target); await _context.SaveChangesAsync(); return(Ok()); } catch (Exception ex) { return(StatusCode(Status400BadRequest, new ResponseMessage { Message = "查無資訊" })); } }
public async Task <IActionResult> Create(Abouts about) { try { _context.Abouts.Add(about); await _context.SaveChangesAsync(); return(Ok()); } catch (Exception ex) { return(StatusCode(Status400BadRequest, new ResponseMessage { Message = ex.Message })); } }
public async Task <IActionResult> Create(HotSaleProducts product) { try { product.Url = "/product/detail?id=" + product.ProductID; _context.HotSaleProducts.Add(product); await _context.SaveChangesAsync(); return(Ok()); } catch (Exception ex) { return(StatusCode(Status400BadRequest, new ResponseMessage { Message = ex.Message })); } }
public async Task <IActionResult> Create(RequestMembers member) { Regex regex = new Regex(@"^(?=.*\d)(?=.*[a-z])(?=.*[A-Z]).{10,30}$"); if (!regex.IsMatch(member.Password)) { return(StatusCode(Status400BadRequest, new ResponseMessage { Message = "字串長度在 10 ~ 30 個字母之間,且至少一個小寫英文字母、大寫英文字母和數字。" })); } if (member.Password != member.CheckPassword) { return(StatusCode(Status400BadRequest, new ResponseMessage { Message = "密碼與確認密碼不符合" })); } member.Password = StringEncryptExtension.aesEncryptBase64(member.Password, member.Email); try { var mem = new Members() { Email = member.Email, IsVerify = member.IsVerify, Name = member.Name, Password = member.Password }; _context.Add(mem); await _context.SaveChangesAsync(); return(Ok()); } catch (Exception ex) { return(StatusCode(Status400BadRequest, new ResponseMessage { Message = "註冊失敗" })); } }
public async Task <IActionResult> Create(RequestBlog blog) { try { if (blog.file != null) { var savePath = Path.Combine(Directory.GetCurrentDirectory(), @"wwwroot\Upload", blog.file.FileName); using (var stream = new FileStream(savePath, FileMode.Create)) { await blog.file.CopyToAsync(stream); } blog.ImgUrl = "/Upload/" + blog.file.FileName; } var target = new Blogs() { ImgUrl = blog.ImgUrl, SubContent = blog.SubContent, Type = Guid.Parse(blog.Type), VideoUrl = blog.VideoUrl, Content = blog.Content, DownDate = blog.DownDate, PublishDate = blog.PublishDate, Title = blog.Title }; _context.Blogs.Add(target); await _context.SaveChangesAsync(); return(Ok()); } catch (Exception ex) { return(StatusCode(Status400BadRequest, new ResponseMessage { Message = ex.Message })); } }
public async Task <IActionResult> Forget(string Account) { var member = _context.Members.Where(r => r.Email == Account); if (member.Any()) { string newPassword = RandomPasswordExtension.CreateRandomPassword(); try { var message = new MimeMessage(); message.From.Add(new MailboxAddress("胡家幸福蜂蜜管理人員", "*****@*****.**")); message.To.Add(new MailboxAddress(member.FirstOrDefault().Name, member.FirstOrDefault().Email)); message.Subject = "忘記密碼重設"; message.Body = new TextPart("plain") { Text = @"你好,你的新密碼為" + newPassword + ",請使用此密碼重新登入並重設密碼。" }; using (var client = new SmtpClient()) { // For demo-purposes, accept all SSL certificates (in case the server supports STARTTLS) client.ServerCertificateValidationCallback = (s, c, h, e) => true; client.Connect("smtp.office365.com", 587, false); // Note: only needed if the SMTP server requires authentication client.Authenticate("*****@*****.**", "RGIRaal2"); await client.SendAsync(message); client.Disconnect(true); } } catch (Exception ex) { return(StatusCode(Status400BadRequest, new ResponseMessage { Message = "發信失敗" })); } member.FirstOrDefault().Password = StringEncryptExtension.aesEncryptBase64(newPassword, member.FirstOrDefault().Email); await _context.SaveChangesAsync(); } return(Ok()); }
public async Task <IActionResult> Create(RequestPD product) { var ProductID = Guid.NewGuid(); product.ID = ProductID.ToString(); var reportFiles = new List <ReportFile>(); if (product.file != null) { var savePath = Path.Combine(Directory.GetCurrentDirectory(), @"wwwroot\Upload", product.file.FileName); using (var stream = new FileStream(savePath, FileMode.Create)) { await product.file.CopyToAsync(stream); } product.ImgUrl = "/Upload/" + product.file.FileName; } if (product.Reportfile != null) { foreach (var item in product.Reportfile) { var savePath = Path.Combine(Directory.GetCurrentDirectory(), @"wwwroot\Upload", item.FileName); using (var stream = new FileStream(savePath, FileMode.Create)) { await item.CopyToAsync(stream); } reportFiles.Add(new ReportFile() { ProductID = ProductID, FileName = item.FileName, Path = "/Upload/" + item.FileName }); _context.ReportFile.AddRange(reportFiles); await _context.SaveChangesAsync(); } } try { var target = new Products() { ID = ProductID, BuyUrl = product.BuyUrl, ImgUrl = product.ImgUrl, DownDate = product.DownDate, Information = product.Information, IsPromotion = product.IsPromotion, Name = product.Name, Price = product.Price, PublishDate = product.PublishDate, SalePrice = product.SalePrice.Value, SubTitle = product.SubTitle, Weight = product.Weight, Standard = product.Standard }; _context.Products.Add(target); await _context.SaveChangesAsync(); return(Ok()); } catch (Exception ex) { return(StatusCode(Status400BadRequest, new ResponseMessage { Message = "查無資訊" })); } }