public async Task <IActionResult> PutBooking(int id, Booking booking)
        {
            if (id != booking.Id)
            {
                return(BadRequest());
            }
            var bookingToEdit = _context.Bookings.FirstOrDefault(x => x.Id == id);

            bookingToEdit.StartDate = booking.StartDate;
            bookingToEdit.EndDate   = booking.EndDate;
            if (booking.ToolId != null && booking.ToolId != 0)
            {
                bookingToEdit.ToolId = booking.ToolId;
            }
            _context.Entry(bookingToEdit).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!BookingExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
Example #2
0
 public ActionResult Edit([Bind(Include = "ToolID,Title,Description,Tag,CoverImagePath,GalleryPath,DocumentationPath,InstallationPath,VideoPath")] Tool tool)
 {
     if (ModelState.IsValid)
     {
         db.Entry(tool).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(tool));
 }
 public ActionResult Edit([Bind(Include = "ID,LastName,FirstMidName,salutation,JoinedDate,JobTitle,Department,CompanyEmail,ResumePath,DisplayPhotoPath")] Employee employee)
 {
     if (ModelState.IsValid)
     {
         db.Entry(employee).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(employee));
 }
Example #4
0
        public IActionResult SaveEditedTool(int id, string start, string end)
        {
            try
            {
                var booking = Context.Bookings.FirstOrDefault(x => x.Id == id);
                if (booking == null)
                {
                    return(BadRequest());
                }
                booking.StartDate            = DateTime.Parse(start);
                booking.EndDate              = DateTime.Parse(end);
                Context.Entry(booking).State = Microsoft.EntityFrameworkCore.EntityState.Modified;
                Context.SaveChanges();

                return(Ok());
            }
            catch (Exception ex)
            {
                return(BadRequest());
            }
        }
Example #5
0
        public ActionResult Edit([Bind(Include = "ToolID,Title,Description,Tag,CoverImagePath,GalleryPath,DocumentationPath,InstallationPath,VideoPath,CoverImageFile,DocumentationFile,InstallationFile,VideoFile,GalleryFiles")] Tool tool)
        {
            //var ID = tool.CoverImagePath;

            if (ModelState.IsValid)
            {
                //Edit cover image
                if (tool.CoverImageFile != null)
                {
                    //cover photo
                    string imageName      = Path.GetFileNameWithoutExtension(tool.CoverImageFile.FileName); //image
                    string imageExtension = Path.GetExtension(tool.CoverImageFile.FileName);                //.jpg
                    string coverFullName  = imageName + imageExtension;                                     //image.jpg

                    string oldCoverImage = Request.MapPath(TempData["CoverImagePath"].ToString());

                    tool.CoverImagePath = "~/Assets/Tools/" + tool.Title + "/cover folder/" + coverFullName;  //  ~/Assets/products/software1/cover image/image.jpg
                    coverFullName       = Path.Combine(Server.MapPath("~/Assets/Tools/" + tool.Title + "/cover folder/" + coverFullName));

                    //Delete old cover image
                    if (System.IO.File.Exists(oldCoverImage))
                    {
                        System.IO.File.Delete(oldCoverImage);
                    }
                    tool.CoverImageFile.SaveAs(coverFullName);
                }
                //if no file chose keep the original
                else
                {
                    tool.CoverImagePath = TempData["CoverImagePath"].ToString();
                }

                //Edit video
                if (tool.CoverImageFile != null)
                {
                    //cover photo
                    string imageName      = Path.GetFileNameWithoutExtension(tool.CoverImageFile.FileName); //image
                    string imageExtension = Path.GetExtension(tool.CoverImageFile.FileName);                //.jpg
                    string coverFullName  = imageName + imageExtension;                                     //image.jpg

                    string oldCoverImage = Request.MapPath(TempData["CoverImagePath"].ToString());

                    tool.CoverImagePath = "~/Assets/Tools/" + tool.Title + "/cover folder/" + coverFullName;  //  ~/Assets/products/software1/cover image/image.jpg
                    coverFullName       = Path.Combine(Server.MapPath("~/Assets/Tools/" + tool.Title + "/cover folder/" + coverFullName));

                    //Delete old cover image
                    if (System.IO.File.Exists(oldCoverImage))
                    {
                        System.IO.File.Delete(oldCoverImage);
                    }
                    tool.CoverImageFile.SaveAs(coverFullName);
                }
                else
                {
                    tool.CoverImagePath = TempData["CoverImagePath"].ToString();
                }



                db.Entry(tool).State = EntityState.Modified;
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }
            return(View(tool));
        }
Example #6
0
        public ActionResult Edit(ToolViewModel toolView)
        {
            if (ModelState.IsValid)
            {
                var MyTool = db.Tools.Find(toolView.ID);

                //Edit cover image
                if (toolView.CoverImageFile != null)
                {
                    //cover photo
                    string imageName      = Path.GetFileNameWithoutExtension(toolView.CoverImageFile.FileName); //image
                    string imageExtension = Path.GetExtension(toolView.CoverImageFile.FileName);                //.jpg
                    string coverFullName  = imageName + imageExtension;                                         //image.jpg

                    string oldCoverImage = Request.MapPath(TempData["CoverImagePath"].ToString());

                    MyTool.CoverImagePath = "~/Assets/Tools" + toolView.tool.ToolID + "/cover folder/" + coverFullName;  //  ~/Assets/products/software1/cover image/image.jpg
                    coverFullName         = Path.Combine(Server.MapPath("C:/Users/Adoca/source/repos/ASM_Tools/Assets/Tools" + toolView.tool.ToolID + "/cover folder/" + coverFullName));

                    //Delete old cover image
                    if (System.IO.File.Exists(oldCoverImage))
                    {
                        System.IO.File.Delete(oldCoverImage);
                    }

                    MyTool.CoverImageFile = toolView.CoverImageFile;
                    MyTool.CoverImageFile.SaveAs(coverFullName);
                }
                //if no file chose keep the original
                else
                {
                    MyTool.CoverImagePath = TempData["CoverImagePath"].ToString();
                }

                foreach (var item in db.ToolToEmployees)
                {
                    if (item.ID == toolView.tool.ToolID)
                    {
                        db.Entry(item).State = EntityState.Deleted;
                    }
                }

                foreach (var item in toolView.Employees)
                {
                    if (item.Checked)
                    {
                        var role = item.Role;
                        var tee  = from te in db.ToolToEmployees
                                   where te.ToolID == toolView.tool.ToolID && te.EmployeeID == item.Employee.ID
                                   select te;
                        if (tee.Count() == 0)
                        {
                            db.ToolToEmployees.Add(new ToolToEmployee()
                            {
                                ToolID = toolView.tool.ToolID, EmployeeID = item.Employee.ID, Role = item.Role
                            });
                        }
                        else
                        {
                            tee.First().Role = role;
                        }
                    }
                    else
                    {
                        var tee = from te in db.ToolToEmployees
                                  where te.ToolID == toolView.tool.ToolID && te.EmployeeID == item.Employee.ID
                                  select te;
                        if (tee.Count() != 0)
                        {
                            db.ToolToEmployees.Remove(tee.First());
                        }
                    }
                }

                MyTool.Title             = toolView.tool.Title;
                MyTool.Description       = toolView.tool.Description;
                MyTool.Tag               = toolView.tool.Tag;
                MyTool.team              = toolView.tool.team;
                MyTool.GalleryPath       = toolView.tool.GalleryPath;
                MyTool.DocumentationPath = toolView.tool.DocumentationPath;
                MyTool.InstallationPath  = toolView.tool.InstallationPath;
                MyTool.VideoPath         = toolView.tool.VideoPath;

                db.Entry(MyTool).State = EntityState.Modified;
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }
            return(View(toolView));
        }
        public ActionResult Edit(EmployeeViewModel employeeView)
        {
            if (ModelState.IsValid)
            {
                var MyEmployee = db.Employees.Find(employeeView.ID);

                if (employeeView.DisplayPhotoFile != null)
                {
                    //cover photo
                    string imageName      = Path.GetFileNameWithoutExtension(employeeView.DisplayPhotoFile.FileName); //image
                    string imageExtension = Path.GetExtension(employeeView.DisplayPhotoFile.FileName);                //.jpg
                    string PhotoFullName  = imageName + imageExtension;                                               //image.jpg

                    string oldPhoto = Request.MapPath(TempData["DisplayPhotoPath"].ToString());

                    MyEmployee.DisplayPhotoPath = "~/Assets/Employees/" + employeeView.employee.ID + "/photo folder/" + PhotoFullName;  //  ~/Assets/products/software1/cover image/image.jpg
                    PhotoFullName = Path.Combine(Server.MapPath("~/Assets/Employees/" + employeeView.employee.ID + "/photo folder/" + PhotoFullName));

                    //Delete old cover image
                    if (System.IO.File.Exists(oldPhoto))
                    {
                        System.IO.File.Delete(oldPhoto);
                    }

                    MyEmployee.DisplayPhotoFile = employeeView.DisplayPhotoFile;

                    MyEmployee.DisplayPhotoFile.SaveAs(PhotoFullName);
                }
                //if no file chosen keep the original
                else
                {
                    if (MyEmployee.DisplayPhotoPath != null)
                    {
                        MyEmployee.DisplayPhotoPath = TempData["DisplayPhotoPath"].ToString();
                    }
                }

                if (employeeView.employee.ResumeFile != null)
                {
                    //cover photo
                    string resumeName      = Path.GetFileNameWithoutExtension(employeeView.employee.ResumeFile.FileName); //image
                    string resumeExtension = Path.GetExtension(employeeView.employee.ResumeFile.FileName);                //.jpg
                    string ResumeFullName  = resumeName + resumeExtension;                                                //image.jpg

                    string oldResume = Request.MapPath(TempData["ResumePath"].ToString());

                    MyEmployee.ResumePath = "~/Assets/Employees/" + employeeView.employee.ID + "/resume folder/" + ResumeFullName;  //  ~/Assets/products/software1/cover image/image.jpg
                    ResumeFullName        = Path.Combine(Server.MapPath("~/Assets/Employees/" + employeeView.employee.ID + "/resume folder/" + ResumeFullName));

                    //Delete old cover image
                    if (System.IO.File.Exists(oldResume))
                    {
                        System.IO.File.Delete(oldResume);
                    }

                    MyEmployee.ResumeFile = employeeView.ResumeFile;
                    MyEmployee.ResumeFile.SaveAs(ResumeFullName);
                }
                //if no file chose keep the original
                else
                {
                    if (MyEmployee.ResumePath != null)
                    {
                        MyEmployee.ResumePath = TempData["ResumePath"].ToString();
                    }
                }


                foreach (var item in db.ToolToEmployees)
                {
                    if (item.ID == employeeView.employee.ID)
                    {
                        db.Entry(item).State = EntityState.Deleted;
                    }
                }

                foreach (var item in employeeView.Tools)
                {
                    if (item.Checked)
                    {
                        var role = item.Role;
                        var tee  = from te in db.ToolToEmployees
                                   where te.EmployeeID == employeeView.employee.ID && te.ToolID == item.tool.ToolID
                                   select te;
                        if (tee.Count() == 0)
                        {
                            db.ToolToEmployees.Add(new ToolToEmployee()
                            {
                                EmployeeID = employeeView.employee.ID, ToolID = item.tool.ToolID, Role = item.Role
                            });
                        }
                        else
                        {
                            tee.First().Role = role;
                        }
                    }
                    else
                    {
                        var tee = from te in db.ToolToEmployees
                                  where te.EmployeeID == employeeView.employee.ID && te.ToolID == item.tool.ToolID
                                  select te;
                        if (tee.Count() != 0)
                        {
                            db.ToolToEmployees.Remove(tee.First());
                        }
                    }
                }

                MyEmployee.LastName     = employeeView.employee.LastName;
                MyEmployee.FirstMidName = employeeView.employee.FirstMidName;
                MyEmployee.JoinedDate   = employeeView.employee.JoinedDate;
                MyEmployee.Department   = employeeView.employee.Department;
                MyEmployee.JobTitle     = employeeView.employee.JobTitle;
                MyEmployee.CompanyEmail = employeeView.employee.CompanyEmail;
                MyEmployee.team         = employeeView.employee.team;
                MyEmployee.salutation   = employeeView.employee.salutation;



                db.Entry(MyEmployee).State = EntityState.Modified;
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }
            return(View(employeeView));
        }
 public virtual void Update(TEntity item)
 {
     _toolContext.Entry(item).State = EntityState.Modified;
 }