// GET: WebSite public ActionResult Index() { var tbl = new tblAll(); var tbllist = new ListAll(); var queryListMenu = (from data in db.tblMenus where data.StatusMenu == 1 && data.ShowHomeMenu == 1 select data).ToList(); var dataNewProducts = from dataProducts in db.tblProducts join dataCategory in db.tblMenus on dataProducts.IdCategoryProducts equals dataCategory.IdMenu where dataProducts.StatusProducts == 1 orderby dataProducts.IdProducts descending select dataProducts; var queryListPicture = (from data in db.tblPictures // where data.Position==1 select data).ToList(); var querySlider = (from dataSlider in db.tblSliders where dataSlider.StatusSlider == 1 select dataSlider).ToList(); var queryBlogNo = (from dataBlog in db.tblBlogs where dataBlog.StatusBlog == 1 && dataBlog.IsVideo == 0 orderby dataBlog.IdBlog descending select dataBlog).Take(2).ToList(); var queryBlogIs = (from dataBlog in db.tblBlogs where dataBlog.StatusBlog == 1 && dataBlog.IsVideo == 1 orderby dataBlog.IdBlog descending select dataBlog).Take(1).ToList(); tbl.ListMenu = queryListMenu; tbl.ListPicture = queryListPicture; tbl.tblPro = dataNewProducts.ToList(); tbl.ListSlider = querySlider; tbl.ListBlogNo = queryBlogNo; tbl.ListBlogIs = queryBlogIs; return(View(tbl)); }
public CreateManagerViewModel(CreateManager createManagerOpen) { cm = createManagerOpen; Sss = new tblDegree(); sssList = GetSSS(); All = new tblAll(); }
public CreateEmployeViewModel(CreateEmploye ceOpen) { ce = ceOpen; All = new tblAll(); Engagment = new tblEngagment(); EngList = GetEng(); }
public ActionResult EditPro(tblAll productPicture) { tblProduct tblproduct = productPicture.tblProducts; db.Entry(tblproduct).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index", "adminProduct")); }
/// <summary> /// Creates manager and validates input /// </summary> private void CreateManagerExecute() { try { using (Entity context = new Entity()) { CreateManager cm = new CreateManager(); tblAll newAll = new tblAll(); newAll.FirstName = Name; newAll.Surname = Surname; newAll.Email = Mail; newAll.Username = Username; newAll.Pasword = Password; newAll.DateOfBirth = All.DateOfBirth; if (CheckMail(newAll.Email) == false) { MessageBox.Show("E-mail already exists"); } else if (CheckCredentials(newAll.Username) == false) { MessageBox.Show("Username already exists"); } else if (CheckCredentials(newAll.Username) == true && newAll.DateOfBirth < DateTime.Now.AddYears(-18) && CheckMail(newAll.Email) == true) { context.tblAlls.Add(newAll); context.SaveChanges(); tblManager newManager = new tblManager(); newManager.AllIDman = newAll.All_ID; newManager.Experience = Experience; newManager.SSS = Sss.name; newManager.ManagerFlor = Floor; context.tblManagers.Add(newManager); context.SaveChanges(); MessageBox.Show("Manager is created"); Name = ""; Surname = ""; Mail = ""; Username = ""; Password = ""; Experience = 0; Floor = 0; } else if (newAll.DateOfBirth > DateTime.Now.AddYears(-18)) { MessageBox.Show("Manager must be at least 18 years old"); } else { MessageBox.Show("Make sure that every field is populated, especially date of birth."); } } } catch (Exception ex) { MessageBox.Show(ex.ToString()); } }
// GET: adminSavePromotions/Create public ActionResult Create(tblAll tblall) { var datauser = (from dataUser in db.tblUsers where dataUser.StatusUser == 1 select dataUser).ToList(); var datapromotion = (from dataPromo in db.tblPromotions where dataPromo.StatusCode == 1 && dataPromo.DateEndCode >= DateTime.Now select dataPromo).ToList(); tblall.ListUser = datauser; tblall.listPromotion = datapromotion; return(View(tblall)); }
public ActionResult DeleteImg(int idpicture) { tblPicture tblPic = db.tblPictures.Find(idpicture); tblAll proPic = new tblAll(); db.tblPictures.Remove(tblPic); db.SaveChanges(); DeleteIMG(proPic.clPicture.OriginalFilepath); return(View(tblPic)); }
public ActionResult Edit(tblAll tblall) { if (ModelState.IsValid) { db.Entry(tblall.tblProducts).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(tblall)); }
public ActionResult Detail(string id) { var id_ = int.Parse(id.Split('-').Last()); var idcate = db.tblProducts.Where(t => t.IdProducts == id_).Select(e => e.IdCategoryProducts).FirstOrDefault(); tblAll pic = new tblAll { tblProductRel = db.tblProducts.Where(x => x.IdCategoryProducts == idcate).ToList(), tblPro = db.tblProducts.Where(t => t.IdProducts == id_).ToList(), ListPicture = db.tblPictures.Where(x => x.ProductsId == id_).ToList() }; return(View(pic)); }
public void DeleteIMG(string picture) { tblAll vgp = new tblAll(); if (picture == null) { return; } var fo = picture.Substring(0, 3); string dir = Server.MapPath("~/fileUpload/" + fo + "/" + picture); System.IO.File.Delete(dir); }
// GET: adminProduct/Edit/5 public ActionResult Edit(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } tblAll pic = new tblAll { tblProducts = db.tblProducts.Find(id), ListPicture = db.tblPictures.Where(t => t.ProductsId == id).ToList(), ListCategory = db.tblCategories.ToList(), ListType = db.tblTypes.ToList(), ListMenu = db.tblMenus.Where(x => x.IsCategoryMenu == 0).ToList() }; return(View(pic)); }
// GET: adminProduct/Create public ActionResult Create(tblAll _tblproduct) { if (ModelState.IsValid) { db.tblProducts.Add(_tblproduct.tblProducts); db.SaveChanges(); } var dataMenu = (from data in db.tblMenus where data.IsCategoryMenu == 0 select data).ToList(); var dataType = (from data in db.tblTypes select data).ToList(); _tblproduct.ListMenu = dataMenu; _tblproduct.ListType = dataType; return(View(_tblproduct)); }
// GET: adminSavePromotions/Edit/5 public ActionResult Edit(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } tblSavePromotion tblSavePromotion = db.tblSavePromotions.Find(id); tblAll tp = new tblAll { tblSavePromotion = db.tblSavePromotions.Find(id), ListUser = db.tblUsers.ToList(), listPromotion = db.tblPromotions.Where(x => x.StatusCode == 1 && x.DateEndCode >= DateTime.Now).ToList() }; if (tblSavePromotion == null) { return(HttpNotFound()); } return(View(tp)); }
private void CreateEmployeExecute() { try { using (Entity context = new Entity()) { CreateManager cm = new CreateManager(); tblAll newAll = new tblAll(); newAll.FirstName = Name; newAll.Surname = Surname; newAll.Email = Mail; newAll.Username = Username; newAll.Pasword = Password; tblEmploye newEmploye = new tblEmploye(); newEmploye.Gender = Gender; newEmploye.EmployeFlor = Floor; if (CheckCredentials(newAll.Username, newAll.Pasword) == true && CheckGender(newEmploye.Gender) == true && CheckFloor(newEmploye.EmployeFlor.GetValueOrDefault()) == true) { newAll.DateOfBirth = All.DateOfBirth.ToString(); context.tblAlls.Add(newAll); context.SaveChanges(); newEmploye.AllIDemp = newAll.All_ID; newEmploye.Citizenship = Citizen; newEmploye.Engagment = Engagment.engName; context.tblEmployes.Add(newEmploye); context.SaveChanges(); MessageBox.Show("Employe is created"); } else { MessageBox.Show("Possible errors:\nPasword or username already exists\nInvalid gender input\nSelected floor can not be chosen\nbecause it does not have manager"); } } } catch (Exception ex) { MessageBox.Show(ex.ToString()); } }
private void CreateManagerExecute() { try { using (Entity context = new Entity()) { CreateManager cm = new CreateManager(); tblAll newAll = new tblAll(); newAll.FirstName = Name; newAll.Surname = Surname; newAll.Email = Mail; newAll.Username = Username; newAll.Pasword = Password; if (CheckCredentials(newAll.Username, newAll.Pasword) == true) { newAll.DateOfBirth = All.DateOfBirth.ToString(); context.tblAlls.Add(newAll); context.SaveChanges(); tblManager newManager = new tblManager(); newManager.AllIDman = newAll.All_ID; newManager.Experience = Experience; newManager.SSS = Sss.name; newManager.ManagerFlor = Floor; context.tblManagers.Add(newManager); context.SaveChanges(); MessageBox.Show("Manager is created"); } else { MessageBox.Show("Pasword or username already exists"); } } } catch (Exception ex) { MessageBox.Show(ex.ToString()); } }
public void SaveImg(tblAll productPicture) { var t = productPicture.cfile == null ? "" : productPicture.cfile; var file = t.Replace("data:image/png;base64,", ""); var photoBytes = Convert.FromBase64String(file); string format = "jpg"; if (productPicture.isactive == 1) { productPicture.isactive = 1; } else { productPicture.isactive = 2; } var picture = new tblAll { clPicture = new tblPicture { ProductsId = productPicture.idProducts, AngleType = 0, Converted = DateTime.Now, ToCheck = true, Type_id = 1, Title = productPicture.nameImg, Position = productPicture.isactive } }; if (productPicture.idpicture == 0) { var settings = new ResizeSettings(); settings.Scale = ScaleMode.DownscaleOnly; settings.Format = format; //string uploadFolder = picture.DirectoryPhysical; string path = Server.MapPath("~/fileUpload/") + DateTime.Now.Day + DateTime.Now.Month + "/"; // check for directory if (!Directory.Exists(path)) { Directory.CreateDirectory(path); } // filename with placeholder for size if (picture.GetConvertedFileName() == null || string.IsNullOrWhiteSpace(picture.GetConvertedFileName())) { picture.SetFileName(DateTime.Now.Day.ToString() + DateTime.Now.Month.ToString() + "_" + picture.CreateFilename() + "_{0}." + format); } if (picture.GetFilePathPhysical(tblAll.PictureSize.Large) != null) { string dest = path + picture.FileName(tblAll.PictureSize.Large); settings.MaxWidth = 800; settings.MaxHeight = 800; if (picture.WaterMarkLarge == tblAll.WatermarkType.None) { ImageBuilder.Current.Build(photoBytes, dest, settings, false, false); } // save biggest version as original if (string.IsNullOrWhiteSpace(picture.clPicture.OriginalFilepath)) { picture.clPicture.OriginalFilepath = picture.GetFilePath(tblAll.PictureSize.Large); } } if (picture.GetFilePathPhysical(tblAll.PictureSize.Medium) != null) { string dest = path + picture.FileName(tblAll.PictureSize.Medium); settings.MaxWidth = 300; settings.MaxHeight = 300; if (picture.WaterMarkLarge == tblAll.WatermarkType.None) { ImageBuilder.Current.Build(photoBytes, dest, settings, false, false); } // save biggest version as original if (string.IsNullOrWhiteSpace(picture.clPicture.OriginalFilepath)) { picture.clPicture.OriginalFilepath = picture.GetFilePath(tblAll.PictureSize.Medium); } } db.tblPictures.Add(picture.clPicture); db.SaveChanges(); } if (productPicture.idpicture > 0) { tblPicture tblpict = db.tblPictures.Find(productPicture.idpicture); tblpict.Title = productPicture.nameImg; tblpict.Position = productPicture.isactive; db.Entry(tblpict).State = EntityState.Modified; db.SaveChanges(); RedirectToAction("Index", "adminProducts"); } }
private void CreateEmployeExecute() { try { using (Entity context = new Entity()) { CreateManager cm = new CreateManager(); tblAll newAll = new tblAll(); //collecting data from text boxes including validations newAll.FirstName = Name; newAll.Surname = Surname; newAll.Email = Mail; newAll.Username = Username; newAll.Pasword = Password; tblEmploye newEmploye = new tblEmploye(); newEmploye.Gender = Gender; newEmploye.EmployeFlor = Floor; newAll.DateOfBirth = All.DateOfBirth; //email must be unique if (CheckMail(newAll.Email) == false) { MessageBox.Show("E-mail already exists"); } //username must be unique else if (CheckCredentials(newAll.Username) == false) { MessageBox.Show("Username already exists"); } //if everything is ok than proced with saving else if (CheckCredentials(newAll.Username) == true && CheckGender(newEmploye.Gender) == true && CheckFloor(newEmploye.EmployeFlor.GetValueOrDefault()) == true && newAll.DateOfBirth < DateTime.Now.AddYears(-18) && CheckMail(newAll.Email) == true) { context.tblAlls.Add(newAll); context.SaveChanges(); //give ID from user table to foreign key in employe table newEmploye.AllIDemp = newAll.All_ID; newEmploye.Citizenship = Citizen; newEmploye.Engagment = Engagment.engName; context.tblEmployes.Add(newEmploye); context.SaveChanges(); MessageBox.Show("Employe is created"); Name = ""; Surname = ""; Mail = ""; Username = ""; Password = ""; Gender = ""; Floor = 0; Citizen = ""; } //NOTE: look at message boxes and you will realise what is the problem else if (CheckFloor(newEmploye.EmployeFlor.GetValueOrDefault()) == false) { MessageBox.Show("Input for floor must be changed because selected floor does not have manager"); } else if (CheckGender(newEmploye.Gender) == false) { MessageBox.Show("Invalid gender input"); } else if (newAll.DateOfBirth > DateTime.Now.AddYears(-18)) { MessageBox.Show("Employe must be at least 18 years old"); } else { MessageBox.Show("Make sure that all fields contain valid values"); } } } catch (Exception ex) { MessageBox.Show(ex.ToString()); } }