public ActionResult Create([Bind(Include = "LocationId,Name,Description,Latitude,Longitude,ZIndex")] Location location) { //check if location object is valid and then add him to db.Location, finally return to Index page if (ModelState.IsValid) { db.Locations.Add(location); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(location)); }
public ActionResult Create([Bind(Include = "OrderID,CustomerID,VacationPackageID,PassengersNum,Total,OrderDate")] Order order) { //check if order object is valid and then calculate total price, add him to db.Order and finally return to end order page if (ModelState.IsValid) { var singlePrice = db.VacationPackages.Find(order.VacationPackageID).SinglePay; order.Total = singlePrice * order.PassengersNum; order.OrderDate = DateTime.Now; db.Orders.Add(order); db.SaveChanges(); return(RedirectToAction("endOrder", "Order", new { id = order.OrderID })); } ViewBag.CustomerID = new SelectList(db.Customers, "CustomerID", "PassportNum", order.CustomerID); ViewBag.VacationPackageID = new SelectList(db.VacationPackages, "VacationPackageID", "Destination", order.VacationPackageID); return(View(order)); }
public ActionResult Create(VacationPackage vacationpackage, HttpPostedFileBase file) { //check if VacationPackage object is valid and then add him to db.Suppliers, finally return to supplier Index page if (ModelState.IsValid) { //check if file is not null if (file != null) { //save upload image in project and his name in db file.SaveAs(HttpContext.Server.MapPath("~/img/") + file.FileName); vacationpackage.Image = file.FileName; } //add package to db.VacationPackage and return to Index page db.VacationPackages.Add(vacationpackage); db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.SupplierID = new SelectList(db.Suppliers, "SupplierID", "SupplierName", vacationpackage.SupplierID); return(View(vacationpackage)); }
protected void Button1_Click(object sender, EventArgs e) { if (Session["EmployeeType"].ToString() == "Rep") { DateTime first_date = new DateTime(DateTime.Today.Year, DateTime.Today.Month, 1); DateTime last_date = new DateTime(DateTime.Today.Year, DateTime.Today.Month, DateTime.DaysInMonth(DateTime.Today.Year, DateTime.Today.Month)); var today = DateTime.Now; var tomorrow = today.AddDays(1); var yesterday = today.AddDays(-1); var month = DateTime.Now.Month.ToString(); con = new SqlConnection(ConfigurationManager.ConnectionStrings["AmounCrmConnectionString"].ConnectionString); SqlCommand cmd2 = new SqlCommand("select CycleID from Cycles where IsCurrent=1"); cmd2.CommandType = CommandType.Text; con.Open(); cmd2.Connection = con; int cycleid = (int)cmd2.ExecuteScalar(); con.Close(); con = new SqlConnection(ConfigurationManager.ConnectionStrings["AmounCrmConnectionString"].ConnectionString); SqlCommand cmd22 = new SqlCommand("select MonthID from Cycles where IsCurrent=1"); cmd22.CommandType = CommandType.Text; con.Open(); cmd22.Connection = con; int cyclemonth = (int)cmd22.ExecuteScalar(); con.Close(); if (month != cyclemonth.ToString()) { VacationslblSaveStatus.Text = "You can't register a vacation beyond the current cycle"; return; } if (Session["CycleID"].ToString() != cycleid.ToString()) { VacationslblSaveStatus.Text = "You can't register a vacation beyond the current cycle"; return; } if (dpStartDate.SelectedDate.Value.Date < yesterday.Date)//Modified to take a Date Part in a consideration, Ehab(4-Mar-2018) Reviewe before publishing { VacationslblSaveStatus.Text = "Invalid Start Date,it must be within 24 hour by maximum"; return; } if (dpStartDate.SelectedDate > last_date || dpStartDate.SelectedDate < first_date) { VacationslblSaveStatus.Text = "Invalid Start Date,it must be within this month"; return; } if (dpEndDate.SelectedDate > last_date || dpEndDate.SelectedDate < first_date) { VacationslblSaveStatus.Text = "Invalid End Date,it must be within this month"; return; } if (dpStartDate.SelectedDate == null || dpEndDate.SelectedDate == null || txtNoOfDays.Text == "" || ddlVacationType.SelectedValue == "0") { VacationslblSaveStatus.Text = "All fields are mandatory"; return; } if (dpEndDate.SelectedDate < dpStartDate.SelectedDate) { VacationslblSaveStatus.Text = "Invalid End Date"; return; } if (int.Parse(ddlVacationType.SelectedValue) == 2 && dpStartDate.SelectedDate > today) { VacationslblSaveStatus.Text = "Invalid Vacation type, Emergency Vaction must be within 24 hour by maximum"; return; } int EmpID = int.Parse(Session["EmployeeID"].ToString()); using (VacationDBContext db = new VacationDBContext()) { Vacation VacationData = (from Vacation_tbl in db.Vacations where Vacation_tbl.EmpID == EmpID && Vacation_tbl.StartDate >= first_date && Vacation_tbl.EndDate <= last_date && ((Vacation_tbl.StartDate <= dpStartDate.SelectedDate && Vacation_tbl.EndDate >= dpEndDate.SelectedDate) || (Vacation_tbl.StartDate <= dpStartDate.SelectedDate && Vacation_tbl.EndDate >= dpStartDate.SelectedDate) || (Vacation_tbl.StartDate <= dpEndDate.SelectedDate && Vacation_tbl.EndDate >= dpEndDate.SelectedDate) || (Vacation_tbl.StartDate > dpStartDate.SelectedDate && Vacation_tbl.EndDate < dpEndDate.SelectedDate)) && Vacation_tbl.Deleted == false select Vacation_tbl).FirstOrDefault(); if (VacationData != null) { VacationslblSaveStatus.Text = "You have a vacation in this date range."; //gvVacations.DataSource = VacationData.; //gvVacations.DataBind(); return; } } using (NationalEntities db = new NationalEntities()) { NationalVaccation nationalData = (from nationalVac_tbl in db.NationalVaccations where nationalVac_tbl.Deleted == null && nationalVac_tbl.VaccationDate >= dpStartDate.SelectedDate && nationalVac_tbl.VaccationDate <= dpEndDate.SelectedDate select nationalVac_tbl).FirstOrDefault(); if (nationalData != null) { VacationslblSaveStatus.Text = "You have a National vacation in this date range."; return; } } using (VacationDBContext newvac = new VacationDBContext()) { Vacation vac = new Vacation(); vac.EmpID = int.Parse(Session["EmployeeID"].ToString()); vac.EmpHRCode = int.Parse(Session["EmployeeHRCode"].ToString()); vac.EmpName = Session["EmployeeName"].ToString(); vac.StartDate = dpStartDate.SelectedDate; string start = dpStartDate.SelectedDate.ToString(); vac.EndDate = dpEndDate.SelectedDate; vac.RequestDate = DateTime.Today; vac.Deleted = false; vac.NoOfDayes = int.Parse(txtNoOfDays.Text); vac.CycleID = int.Parse(Session["CycleID"].ToString()); vac.VacationTypeID = int.Parse(ddlVacationType.SelectedValue); vac.VacationType = ddlVacationType.SelectedItem.ToString(); using (EmployeesViewDBContext Empdb = new EmployeesViewDBContext()) { View_Employees EmpData = (from Emp_tbl in Empdb.View_Employees where Emp_tbl.EmployeeID == vac.EmpID select Emp_tbl).FirstOrDefault(); vac.DMID = EmpData.DirectManagerID; } newvac.Vacations.Add(vac); int roweffected = newvac.SaveChanges(); if (roweffected > 0) { VacationslblSaveStatus.Text = "Saved"; Clear(); LoadVacations(); } else { VacationslblSaveStatus.Text = "Error"; } } } }
protected void btnDelete_Click(object sender, EventArgs e) { using (VacationDBContext db = new VacationDBContext()) { DateTime first_date = new DateTime(DateTime.Today.Year, DateTime.Today.Month, 1); DateTime last_date = new DateTime(DateTime.Today.Year, DateTime.Today.Month, DateTime.DaysInMonth(DateTime.Today.Year, DateTime.Today.Month)); var today = DateTime.Today; var tomorrow = today.AddDays(1); var yesterday = today.AddDays(-1); if (dpStartDate.SelectedDate.Value.Date < yesterday.Date) { VacationslblSaveStatus.Text = "You can't delete this vacation,it must be within 24 hour by maximum"; Clear(); return; } if (dpStartDate.SelectedDate > last_date || dpStartDate.SelectedDate < first_date) { VacationslblSaveStatus.Text = "Invalid Start Date,it must be within this month"; return; } if (dpEndDate.SelectedDate > last_date || dpEndDate.SelectedDate < first_date) { VacationslblSaveStatus.Text = "Invalid End Date,it must be within this month"; return; } if (dpStartDate.SelectedDate == null || dpEndDate.SelectedDate == null || txtNoOfDays.Text == "" || ddlVacationType.SelectedValue == "0") { VacationslblSaveStatus.Text = "All fields is mandatory"; return; } if (dpEndDate.SelectedDate < dpStartDate.SelectedDate) { VacationslblSaveStatus.Text = "Invalid End Date"; return; } int ID = int.Parse(txtVacID.Text); Vacation updateVac = (from Vac_tbl in db.Vacations where Vac_tbl.VacationID == ID && Vac_tbl.Deleted == false select Vac_tbl).FirstOrDefault(); if (Session["EmployeeType"].ToString() == "Rep") { updateVac.StartDate = dpStartDate.SelectedDate; updateVac.EndDate = dpEndDate.SelectedDate; updateVac.NoOfDayes = int.Parse(txtNoOfDays.Text); updateVac.VacationTypeID = int.Parse(ddlVacationType.SelectedValue); updateVac.Deleted = true; //updateVac.RequestDate = DateTime.Today; } int roweffected = db.SaveChanges(); if (roweffected > 0) { VacationslblSaveStatus.Text = "Deleted"; gvVacations.DataSource = null; gvVacations.DataBind(); LoadVacations(); Clear(); } else { VacationslblSaveStatus.Text = "Error"; } } }
protected void btnUpdate_Click(object sender, EventArgs e) { using (VacationDBContext db = new VacationDBContext()) { DateTime first_date = new DateTime(DateTime.Today.Year, DateTime.Today.Month, 1); DateTime last_date = new DateTime(DateTime.Today.Year, DateTime.Today.Month, DateTime.DaysInMonth(DateTime.Today.Year, DateTime.Today.Month)); var today = DateTime.Today; var tomorrow = today.AddDays(1); var yesterday = today.AddDays(-1); if (dpStartDate.SelectedDate.Value.Date < yesterday.Date && dpEndDate.SelectedDate.Value.Date < yesterday) { VacationslblSaveStatus.Text = "Invalid Date,it must be within 24 hour by maximum"; return; } if (dpStartDate.SelectedDate > last_date || dpStartDate.SelectedDate < first_date) { VacationslblSaveStatus.Text = "Invalid Start Date,it must be within this month"; return; } if (dpEndDate.SelectedDate > last_date || dpEndDate.SelectedDate < first_date) { VacationslblSaveStatus.Text = "Invalid End Date,it must be within this month"; return; } if (dpStartDate.SelectedDate == null || dpEndDate.SelectedDate == null || txtNoOfDays.Text == "" || ddlVacationType.SelectedValue == "0") { VacationslblSaveStatus.Text = "All fields is mandatory"; return; } if (dpEndDate.SelectedDate < dpStartDate.SelectedDate) { VacationslblSaveStatus.Text = "Invalid End Date"; return; } if (int.Parse(ddlVacationType.SelectedValue) == 2 && dpStartDate.SelectedDate > today) { VacationslblSaveStatus.Text = "Invalid Vacation type, Emergency Vaction must be within 24 hour by maximum"; return; } int EmpID = int.Parse(Session["EmployeeID"].ToString()); int VacID = int.Parse(txtVacID.Text); using (VacationDBContext db1 = new VacationDBContext()) { Vacation VacationData = (from Vacation_tbl in db1.Vacations where Vacation_tbl.EmpID == EmpID && Vacation_tbl.StartDate >= first_date && Vacation_tbl.EndDate <= last_date && ((Vacation_tbl.StartDate <= dpStartDate.SelectedDate && Vacation_tbl.EndDate >= dpEndDate.SelectedDate) || (Vacation_tbl.StartDate <= dpStartDate.SelectedDate && Vacation_tbl.EndDate >= dpStartDate.SelectedDate) || (Vacation_tbl.StartDate <= dpEndDate.SelectedDate && Vacation_tbl.EndDate >= dpEndDate.SelectedDate) || (Vacation_tbl.StartDate > dpStartDate.SelectedDate && Vacation_tbl.EndDate < dpEndDate.SelectedDate)) && Vacation_tbl.Deleted == false && Vacation_tbl.VacationID != VacID select Vacation_tbl).FirstOrDefault(); if (VacationData != null) { VacationslblSaveStatus.Text = "You have a vacation in this date range."; //gvVacations.DataSource = VacationData.; //gvVacations.DataBind(); return; } } using (NationalEntities db2 = new NationalEntities()) { NationalVaccation nationalData = (from nationalVac_tbl in db2.NationalVaccations where nationalVac_tbl.Deleted == null && nationalVac_tbl.VaccationDate >= dpStartDate.SelectedDate && nationalVac_tbl.VaccationDate <= dpEndDate.SelectedDate select nationalVac_tbl).FirstOrDefault(); if (nationalData != null) { VacationslblSaveStatus.Text = "You have a National vacation in this date range."; return; } } int ID = int.Parse(txtVacID.Text); Vacation updateVac = (from Vac_tbl in db.Vacations where Vac_tbl.VacationID == ID && Vac_tbl.Deleted == false select Vac_tbl).FirstOrDefault(); if (Session["EmployeeType"].ToString() == "Rep") { updateVac.StartDate = dpStartDate.SelectedDate; updateVac.EndDate = dpEndDate.SelectedDate; updateVac.NoOfDayes = int.Parse(txtNoOfDays.Text); updateVac.VacationTypeID = int.Parse(ddlVacationType.SelectedValue); updateVac.VacationType = ddlVacationType.SelectedItem.ToString(); //updateVac.RequestDate = DateTime.Today; } int roweffected = db.SaveChanges(); if (roweffected > 0) { VacationslblSaveStatus.Text = "Updated"; gvVacations.DataSource = null; gvVacations.DataBind(); LoadVacations(); Clear(); } else { VacationslblSaveStatus.Text = "Error"; } } }