public async Task <IActionResult> AddToCart([Bind("id,ProductName,Price,Discount")] Cart cart, string proName, double?price, int?discount, long postId) { string id = User.FindFirst(ClaimTypes.NameIdentifier)?.Value; if (id == null) { TempData["msg"] = "انت غير مسجل معنا"; return(RedirectToAction("PostView", new { id = postId })); } if (!string.IsNullOrEmpty(proName) && price != null) { if (!GetCartProductName(proName, id)) { cart.ProductName = proName; cart.Price = price; cart.Discount = discount; cart.UserId = id; db.Add(cart); await db.SaveChangesAsync(); cartCount = CartCount(); } else { TempData["msg"] = "اسم المنتج: (" + proName + ") موجود مسبقا بقائمتك"; } } return(RedirectToAction("PostView", new { id = postId })); }
public void SaveTransaction(TransactionData transactionData, ApplicationDb context, int ownerID) { TransactionDescription transDesc = new TransactionDescription(); transDesc.Type = transactionData.Type; transDesc.Description = transactionData.Description; transDesc.Date = DateTime.Now; transDesc.ownerID = ownerID; context.Add(transDesc); context.SaveChanges(); var id = transDesc.ID; foreach (ProductsViewModel product in transactionData.Products) { Transaction trans = new Transaction(); trans.TransactionDescriptionID = id; trans.ProductID = product.ID; trans.UnitNetPrice = product.NetPrice; trans.UnitGrossPrice = product.GrossPrice; trans.ProductUnits = product.Units; trans.GrossPrice = product.GrossPrice * product.Units; trans.NetPrice = product.NetPrice * product.Units; context.Add(trans); context.SaveChanges(); } UpdateProductUnits(transactionData, context); }
public async Task <IActionResult> Create([Bind("id,firstName,lastName,UserName,Email,Address,Country,Zip")] BillingAddress billingAddress) { if (ModelState.IsValid) { _context.Add(billingAddress); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(billingAddress)); }
public async Task <IActionResult> Create([Bind("id,catName")] Category category) { if (ModelState.IsValid) { _context.Add(category); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(category)); }
public async Task <IActionResult> Create([Bind("id,ProductName,Price,Discount")] Cart cart) { if (ModelState.IsValid) { _context.Add(cart); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(cart)); }
public async Task <IActionResult> Create([Bind("ID,TransactionID,Type,ProductID,ProductNetPrice,ProductGrossPrice,Date")] Transaction transaction) { if (ModelState.IsValid) { _context.Add(transaction); await _context.SaveChangesAsync(); return(RedirectToAction("Index")); } return(View(transaction)); }
public async Task <IActionResult> Create([Bind("ID,FirstName,LastName,ClientEmail,Street,Town,PostalCode,Voivodeship,Country,ownerID")] ClientsViewModel client) { if (ModelState.IsValid) { client.ownerID = HttpContext.Session.GetObjectFromJson <int>("ownerID"); _context.Add(ClientMapper.MapViewToClient(client)); await _context.SaveChangesAsync(); return(RedirectToAction("Index")); } return(View(client)); }
public async Task <IActionResult> Create([Bind("ID,Name,Trade,CompanyEmail,Street,Town,PostalCode,Voivodeship,Country,OwnerID")] CompaniesViewModel company) { if (ModelState.IsValid) { company.ownerID = HttpContext.Session.GetObjectFromJson <int>("ownerID"); _context.Add(CompanyMapper.MapViewToCompany(company)); await _context.SaveChangesAsync(); return(RedirectToAction("Index")); } return(View(company)); }
public async Task <IActionResult> Create([Bind("id,SubCatName,catId")] SubCategory subCategory) { if (ModelState.IsValid) { _context.Add(subCategory); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } ViewData["catId"] = new SelectList(_context.Categories, "id", "catName", subCategory.catId); return(View(subCategory)); }
public async Task <IActionResult> Create(EmployeesViewModel employee) { if (ModelState.IsValid) { employee.ownerID = HttpContext.Session.GetObjectFromJson <int>("ownerID"); _context.Add(EmployeeMapper.MapViewToEmployee(employee)); await _context.SaveChangesAsync(); return(RedirectToAction("Index")); } return(View(employee)); }
private void Seed() { using var context = new ApplicationDb(ContextOptions); context.Database.EnsureDeleted(); context.Database.EnsureCreated(); var company1 = new CompanyData { Name = "One", Url = "CompanyPageTest.html" }; context.Add(company1); context.SaveChanges(); }
public async Task <IActionResult> Create([Bind("ID,Name,Description,NetPrice,GrossPrice,Quantity")] ProductsViewModel product) { if (ModelState.IsValid) { product.ownerID = HttpContext.Session.GetObjectFromJson <int>("ownerID"); product.GrossPrice = product.NetPrice * 1.23M; _context.Add(ProductMapper.MapViewToProduct(product)); await _context.SaveChangesAsync(); return(RedirectToAction("Index")); } return(View(product)); }
public async Task <IActionResult> Create([Bind("id,cardType,cardName,cardNumber,expiration,cvv,cartId,billingId")] Payment payment) { if (ModelState.IsValid) { _context.Add(payment); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } ViewData["cartId"] = new SelectList(_context.Carts, "id", "id", payment.cartId); ViewData["billingId"] = new SelectList(_context.BillingAddresses, "id", "Address", payment.billingId); return(View(payment)); }
// Register Settings ************************************** public async Task InsertUserSetting() { UserSetting userSetting = new UserSetting(); userSetting.isEmailConfirm = true; userSetting.isRegisterOpen = true; userSetting.MinimumPassLength = 1; userSetting.MaxPassLength = 25; userSetting.isDigit = false; userSetting.isUpper = false; userSetting.SendWelcomeMessage = false; db.Add(userSetting); await db.SaveChangesAsync(); }
public async Task <IActionResult> SaveEmail(int id) { int ownerId = HttpContext.Session.GetObjectFromJson <int>("ownerID"); Email msg = HttpContext.Session.GetItemOfSessionList <Email>(string.Format("ReceivedEmails-{0}", ownerId), id); msg.OwnerID = ownerId; msg.Saved = true; _context.Add(msg); await _context.SaveChangesAsync(); es.SetEmailAsRead(msg.Uid); HttpContext.Session.RemoveFromSessionList <Email>(string.Format("ReceivedEmails-{0}", ownerId), id); return(RedirectToAction("ReceiveEmails")); }
private int CreateOwner(string userID, RegisterViewModel model) { Owner owner = new Owner(); owner.FirstName = model.FirstName; owner.LastName = model.LastName; owner.Created = DateTime.Now; owner.OwnerEmail = model.Email; owner.UserId = userID; _context.Add(owner); _context.SaveChanges(); return(owner.ID); }
public async Task <IActionResult> Create([Bind("id,Title,PostContent,PostImg,Auther,PostDate,PostViews,PostLike,LikeUserName,SubId,IsPublish,ProductName,Price,Discount")] Post post, IFormFile img) { ViewBag.msg = string.Empty; string id = User.FindFirst(ClaimTypes.Name)?.Value; if (id == null) { return(NotFound()); } string newFileName = string.Empty; if (img != null && img.Length > 0) { newFileName = img.FileName; if (IsImageValidate(newFileName)) { string filename = Path.Combine(host.WebRootPath + "/images/Post", newFileName); await img.CopyToAsync(new FileStream(filename, FileMode.Create)); } else { ViewBag.msg = "الملفات المسموح بها : png, jpeg, jpg, gif, bmp"; return(View()); } } try { post.Auther = id; post.LikeUserName = ""; post.PostDate = DateTime.Now; post.PostImg = newFileName; post.PostLike = 0; post.PostViews = 0; _context.Add(post); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } catch { } ViewData["SubId"] = new SelectList(_context.SubCategories, "id", "SubCatName", post.SubId); return(View(post)); }
public async Task <IActionResult> Create([Bind("id,UserName,Email,Password,PasswordConfirm,Phone,EmailConfirm")] AppUser appUser) { Message = string.Empty; successMsg = string.Empty; if (ModelState.IsValid) { string input = appUser.Password; if (!string.IsNullOrEmpty(input)) { DataTable dt = new DataTable(); Users users = new Users(); string userName = appUser.UserName; string email = appUser.Email; dt = users.CheckUserNameExist(userName); if (dt.Rows.Count < 1) { if (!IsEmailAddressExist(email)) { appUser.Password = AppHash.HashPassword(input); appUser.PasswordConfirm = AppHash.HashPassword(input); _context.Add(appUser); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } else { Message = "البريد الالكتروني المدخل (" + email + ") مستعمل"; return(View()); } } else { Message = "اسم المستخدم المدخل (" + userName + ") مستعمل"; return(View()); } } } return(View(appUser)); }
private void Seed() { using var context = new ApplicationDb(ContextOptions); context.Database.EnsureDeleted(); context.Database.EnsureCreated(); var company1 = new CompanyData { Name = "One" }; var productJson1 = new ProductJson { Title = "One" }; var productJson2 = new ProductJson { Title = "Two" }; var productJson3 = new ProductJson { Title = "Three" }; var product1 = new ProductData { Title = "One", JsonData = JsonConvert.SerializeObject(productJson1), Url = "Url1", ExternalId = "1", ProductState = ProductState.Success }; var product2 = new ProductData { Title = "Two", JsonData = JsonConvert.SerializeObject(productJson2), Url = "Url2", ExternalId = "2" }; var product3 = new ProductData { Title = "Three", JsonData = JsonConvert.SerializeObject(productJson3), Url = "Url3", ExternalId = "3" }; var category1 = new CategoryData { Name = "One" }; var category2 = new CategoryData { Name = "Two", SupCategoryData = category1 }; var category3 = new CategoryData { Name = "Three", SupCategoryData = category2 }; product1.Categories = new List <CategoryData> { category1, category2, category3 }; product2.Categories = new List <CategoryData> { category1, category2 }; product3.Categories = new List <CategoryData> { category1 }; company1.Products = new List <ProductData> { product1, product2, product3 }; context.Add(company1); context.SaveChanges(); }
public async Task <IActionResult> Register([Bind("id, UserName, Email, Password, PasswordConfirm, Phone, EmailConfirm")] AppUser appUser) { Message = string.Empty; successMsg = string.Empty; if (ModelState.IsValid) { if (!string.IsNullOrEmpty(IsEmailConfirm())) { if (IsEmailConfirm() == "true") { appUser.EmailConfirm = true; } else { appUser.EmailConfirm = false; } } else { appUser.EmailConfirm = false; } string input = appUser.Password; if (!string.IsNullOrEmpty(input)) { if (PasswordMinimumLength() > 0 && PasswordMaximumLength() > 0) { int min = PasswordMinimumLength(); int max = PasswordMaximumLength(); if (input.Length < min) { Message = "الخد الأدني لعدد احرف الباسوورد " + min + " مقاطع"; return(View()); } if (input.Length > max) { Message = "الخد الأعلي لعدد احرف الباسوورد " + max + " مقاطع"; return(View()); } } if (!string.IsNullOrEmpty(IsPasswordDigit())) { string isdigit = IsPasswordDigit(); if (isdigit == "true") { if (!input.Any(char.IsDigit)) { Message = "يجب ارفاق علي الاقل رقم واحد بكلمة المرور"; return(View()); } } } if (!string.IsNullOrEmpty(IsPasswordUpper())) { string isupper = IsPasswordUpper(); if (isupper == "true") { if (!input.Any(char.IsUpper)) { Message = "يجب ارفاق علي الاقل حرف كابيتال بكلمة المرور"; return(View()); } } } appUser.Password = AppHash.HashPassword(input); appUser.PasswordConfirm = AppHash.HashPassword(input); DataTable dt = new DataTable(); Users users = new Users(); string userName = appUser.UserName; string email = appUser.Email; dt = users.CheckUserNameExist(userName); if (dt.Rows.Count < 1) { if (!IsEmailAddressExist(email)) { int userCount = db.AppUsers.Count(); db.Add(appUser); string userId = appUser.id; await db.SaveChangesAsync(); string title = "تاكيد اشتراكك بموقع التجربة"; string body = "مرحبا " + userName + "<br />"; body += "يرجي الضغط علي الرابط ادناه لتفعيل اشتراكك بموق التجربة" + "<br />" + "<br />"; body += "https://localhost:44313/Acount/AccountValidate?UId=" + userId; if (SendEmail(email, body, title)) { if (await InsertEmailConfirm(userId)) { successMsg = "تم انشاء حسابك بنجاح يرجي زيارة بريدك الالكتروني لتفعيل حسابك"; if (!string.IsNullOrEmpty(IsSendEmailAfterRegister())) { if (IsSendEmailAfterRegister() == "true") { title = "شكرا لتسجيلك معنا بموقع التجربة"; body = "مرحبا " + userName + "<br />"; body += "شكرا لتسجيلك معنا بموقع التجربة"; SendEmail(email, body, title); } } } else { Message = "خطأ بعملية اضافة الحساب, يرجي المحاولة لاحقا"; } } else { if (await InsertEmailConfirm(userId)) { Message = "تم انشاء حسابك بنجاح وتعذر ارسال رسالة التفعيل الي بريدك الالكتروني"; } } string roleId = string.Empty; if (userCount <= 0) { AppRole appRole = new AppRole(); appRole.RoleName = "Admin"; await db.AddAsync(appRole); await db.SaveChangesAsync(); roleId = appRole.id; appRole.id = Guid.NewGuid().ToString(); appRole.RoleName = "SuperVisor"; await db.AddAsync(appRole); await db.SaveChangesAsync(); appRole.id = Guid.NewGuid().ToString(); appRole.RoleName = "Member"; await db.AddAsync(appRole); await db.SaveChangesAsync(); UserRole userRole = new UserRole(); userRole.RoleId = roleId; userRole.UserId = userId; await db.AddAsync(userRole); await db.SaveChangesAsync(); } else { roleId = Data.AppAuthentication.GetRoleId("Member"); if (!string.IsNullOrEmpty(roleId)) { UserRole userRole = new UserRole(); userRole.RoleId = roleId; userRole.UserId = userId; await db.AddAsync(userRole); await db.SaveChangesAsync(); } } return(RedirectToAction(nameof(Register))); } else { Message = "البريد الالكتروني المدخل (" + email + ") غير متوفر"; return(View()); } } else { Message = "اسم المستخدم المدخل (" + userName + ") غير متوفر"; return(View()); } } } return(RedirectToAction(nameof(Register))); }