예제 #1
0
        public ActionResult Edit(WorkAssignmentsViewModel model)
        {
            WorkAssignments wam = db.WorkAssignments.Find(model.Id_WorkAssignment);

            wam.Title        = model.Title;
            wam.Description  = model.Description;
            wam.Deadline     = model.Deadline.GetValueOrDefault();
            wam.CreatedAt    = model.CreatedAt.GetValueOrDefault();
            wam.InProgress   = model.InProgress;
            wam.InProgressAt = model.InProgressAt.GetValueOrDefault();
            //wam.CompletedAt = model.CompletedAt.GetValueOrDefault();
            wam.CompletedAt    = DateTime.Now;
            wam.Completed      = model.Completed;
            wam.LastModifiedAt = DateTime.Now;
            wam.DeletedAt      = model.DeletedAt.GetValueOrDefault();
            wam.Active         = true;

            int customerId = int.Parse(model.CustomerName);

            if (customerId > 0)
            {
                Customers cus = db.Customers.Find(customerId);
                wam.Id_Customer = cus.Id_Customer;
            }

            ViewBag.CustomerName = new SelectList((from c in db.Customers select new { Id_Customer = c.Id_Customer, CustomerName = c.CustomerName }), "Id_Customer", "CustomerName", wam.Id_Customer);

            db.SaveChanges();
            return(RedirectToAction("Index"));
        }//edit
예제 #2
0
        public ActionResult Create(EmployeesViewModel model)
        {
            MobileWorkDataEntities entities = new MobileWorkDataEntities();

            Employees emp = new Employees();

            emp.Id_Employee       = model.Id_Employee;
            emp.FirstName         = model.FirstName;
            emp.LastName          = model.LastName;
            emp.PhoneNumber       = model.PhoneNumber;
            emp.EmailAddress      = model.EmailAddress;
            emp.EmployeeReference = model.EmployeeReference;
            emp.DeletedAt         = model.DeletedAt;
            emp.Active            = model.Active;
            emp.EmployeePicture   = model.EmployeePicture;

            db.Employees.Add(emp);

            int contractorId = int.Parse(model.CompanyName);

            if (contractorId > 0)
            {
                Contractors con = db.Contractors.Find(contractorId);
                emp.Id_Contractor = con.Id_Contractor;
            }

            int departmentId = int.Parse(model.DepartmentName);

            if (departmentId > 0)
            {
                Departments dep = db.Departments.Find(departmentId);
                emp.Id_Department = dep.Id_Department;
            }

            try
            {
                db.SaveChanges();
            }

            catch (Exception ex)
            {
            }

            ViewBag.DepartmentName = new SelectList((from d in db.Departments select new { Id_Department = d.Id_Department, DepartmentName = d.DepartmentName }), "Id_Department", "DepartmentName", null);

            ViewBag.CompanyName = new SelectList((from c in db.Contractors select new { Id_Contractor = c.Id_Contractor, CustomerName = c.CompanyName }), "Id_Contractor", "CompanyName", null);

            return(RedirectToAction("Index"));
        }//create
예제 #3
0
        public string PutEmployeeImage()
        {
            MobileWorkDataEntities entities = new MobileWorkDataEntities();

            try
            {
                Employees newEmployee = new Employees()
                {
                    FirstName = "Teppo",
                    LastName  = "Testaaja",

                    //EmployeePicture = File.ReadAllBytes(@"C:\TEMP\Matti.png")
                    EmployeePicture = File.ReadAllBytes(@"D:\VisualStudio2017\MobileBackendMVC - Api\MobileBackendMVC - Api\Images\Matti.png")
                };
                entities.Employees.Add(newEmployee);
                entities.SaveChanges();

                return("OK!");
            }
            finally
            {
                entities.Dispose();
            }

            return("Error");
        }
예제 #4
0
        public ActionResult Create(ContractorsViewModel model)
        {
            MobileWorkDataEntities db = new MobileWorkDataEntities();

            Contractors con = new Contractors();

            con.CompanyName    = model.CompanyName;
            con.ContactPerson  = model.ContactPerson;
            con.PhoneNumber    = model.PhoneNumber;
            con.EmailAddress   = model.EmailAddress;
            con.VatId          = model.VatId;
            con.HourlyRate     = model.HourlyRate;
            con.CreatedAt      = DateTime.Now;
            con.LastModifiedAt = DateTime.Now;
            con.DeletedAt      = model.DeletedAt;
            con.Active         = model.Active;

            db.Contractors.Add(con);

            try
            {
                db.SaveChanges();
            }

            catch (Exception ex)
            {
            }

            return(RedirectToAction("Index"));
        }//create
예제 #5
0
        public ActionResult Create(TimeSheetsViewModel model)
        {
            MobileWorkDataEntities entities = new MobileWorkDataEntities();

            Timesheets tsv = new Timesheets();

            tsv.Id_Timesheet   = model.Id_Timesheet;
            tsv.StartTime      = model.StartTime;
            tsv.StopTime       = model.StopTime;
            tsv.Comments       = model.Comments;
            tsv.CreatedAt      = DateTime.Now;
            tsv.LastModifiedAt = DateTime.Now;
            tsv.Active         = model.Active;

            db.Timesheets.Add(tsv);

            int employeeId = int.Parse(model.FirstName);

            if (employeeId > 0)
            {
                Employees emp = db.Employees.Find(employeeId);
                tsv.Id_Employee = emp.Id_Employee;
            }

            int employeeLastId = int.Parse(model.LastName);

            if (employeeLastId > 0)
            {
                Employees emp = db.Employees.Find(employeeLastId);
                tsv.Id_Employee = emp.Id_Employee;
            }

            ViewBag.CustomerName = new SelectList((from c in db.Customers select new { Id_Customer = c.Id_Customer, CustomerName = c.CustomerName }), "Id_Customer", "CustomerName", null);
            ViewBag.CompanyName  = new SelectList((from co in db.Contractors select new { Id_Contractor = co.Id_Contractor, CompanyName = co.CompanyName }), "Id_Contractor", "CompanyName", null);

            try
            {
                db.SaveChanges();
            }

            catch (Exception ex)
            {
            }

            return(RedirectToAction("Index"));
        }//create
예제 #6
0
        public ActionResult Edit(ContractorsViewModel model)
        {
            Contractors con = new Contractors();

            con.CompanyName    = model.CompanyName;
            con.ContactPerson  = model.ContactPerson;
            con.PhoneNumber    = model.PhoneNumber;
            con.EmailAddress   = model.EmailAddress;
            con.VatId          = model.VatId;
            con.HourlyRate     = model.HourlyRate;
            con.CreatedAt      = model.CreatedAt;
            con.LastModifiedAt = DateTime.Now;
            con.DeletedAt      = model.DeletedAt;
            con.Active         = model.Active;

            db.SaveChanges();
            return(View("Index"));
        }//edit
예제 #7
0
        public ActionResult Create(DepartmentsViewModel model)
        {
            MobileWorkDataEntities entities = new MobileWorkDataEntities();


            Departments dep = new Departments();

            dep.DepartmentName = model.DepartmentName;

            db.Departments.Add(dep);

            try
            {
                db.SaveChanges();
            }

            catch (Exception ex)
            {
            }

            return(RedirectToAction("Index"));
        }//create
예제 #8
0
        public ActionResult Create(CustomersViewModel model)
        {
            MobileWorkDataEntities entities = new MobileWorkDataEntities();

            Customers cus = new Customers();

            cus.CustomerName   = model.CustomerName;
            cus.ContactPerson  = model.ContactPerson;
            cus.PhoneNumber    = model.PhoneNumber;
            cus.EmailAddress   = model.EmailAddress;
            cus.CreatedAt      = DateTime.Now;
            cus.LastModifiedAt = DateTime.Now;
            cus.Active         = model.Active;

            db.Customers.Add(cus);

            PinCodes pic = new PinCodes();

            pic.PinCode = model.PinCode;
            //usr.Password = "******";
            pic.Customers   = cus;
            ViewBag.PinCode = new SelectList((from p in db.PinCodes select new { Id_PinCode = p.Id_PinCode, PinCode = p.PinCode }), "Id_PinCode", "PinCode", null);


            db.PinCodes.Add(pic);

            try
            {
                db.SaveChanges();
            }

            catch (Exception ex)
            {
            }

            return(RedirectToAction("Index"));
        }//create
예제 #9
0
        public ActionResult Create(WorkAssignmentsViewModel model)
        {
            MobileWorkDataEntities db = new MobileWorkDataEntities();

            WorkAssignments wam = new WorkAssignments();

            wam.Title          = model.Title;
            wam.Description    = model.Description;
            wam.Deadline       = model.Deadline;
            wam.CreatedAt      = DateTime.Now;
            wam.InProgress     = model.InProgress;
            wam.InProgressAt   = model.InProgressAt;
            wam.CompletedAt    = model.CompletedAt;
            wam.Completed      = model.Completed;
            wam.LastModifiedAt = DateTime.Now;
            wam.Active         = true;;

            db.WorkAssignments.Add(wam);

            int customerId = int.Parse(model.CustomerName);

            if (customerId > 0)
            {
                Customers cus = db.Customers.Find(customerId);
                wam.Id_Customer = cus.Id_Customer;
            }

            ViewBag.CustomerName = new SelectList((from c in db.Customers select new { Id_Customer = c.Id_Customer, CustomerName = c.CustomerName }), "Id_Customer", "CustomerName", null);

            try
            {
                db.SaveChanges();
            }

            catch (Exception ex)
            {
            }

            return(RedirectToAction("Index"));
        }//create
예제 #10
0
        [HttpPost] //verbiattribuutti
        public bool PostStatus(WorkAssignmentOperationModel input)
        {
            MobileWorkDataEntities entities = new MobileWorkDataEntities();

            try
            {
                WorkAssignments assignment = (from wa in entities.WorkAssignments
                                              where (wa.Active == true) &&
                                              (wa.Title == input.AssignmentTitle)
                                              select wa).FirstOrDefault();

                if (assignment == null)
                {
                    return(false);
                }

                //NumberStyles style;
                //CultureInfo provider;
                //provider = new CultureInfo("fi-FI");
                //string valueString = input.Latitude.ToString("R", CultureInfo.InvariantCulture);
                //style = NumberStyles.AllowDecimalPoint;


                if (input.Operation == "Start")
                {
                    int assignmentId = assignment.Id_WorkAssignment;

                    Timesheets newEntry = new Timesheets()
                    {
                        Id_WorkAssignment = assignmentId,
                        StartTime         = DateTime.Now,
                        WorkComplete      = false,
                        Active            = true,
                        CreatedAt         = DateTime.Now
                    };
                    entities.Timesheets.Add(newEntry);
                }
                else if (input.Operation == "Stop")
                {
                    int assignmentId = assignment.Id_WorkAssignment;

                    Timesheets existing = (from ts in entities.Timesheets
                                           where (ts.Id_WorkAssignment == assignmentId) &&
                                           (ts.Active == true) && (ts.WorkComplete == false)
                                           orderby ts.StartTime descending
                                           select ts).FirstOrDefault();

                    if (existing != null)
                    {
                        existing.StopTime       = DateTime.Now;
                        existing.WorkComplete   = true;
                        existing.LastModifiedAt = DateTime.Now;
                    }
                    else
                    {
                        return(false);
                    }
                }
                entities.SaveChanges();
            }
            catch
            {
                return(false);
            }
            finally
            {
                entities.Dispose();
            }
            return(true);
        }
예제 #11
0
        public ActionResult Create(PinCodesViewModel model)
        {
            MobileWorkDataEntities entities = new MobileWorkDataEntities();

            PinCodes pin = new PinCodes();

            pin.Id_PinCode     = model.Id_PinCode;
            pin.PinCode        = model.PinCode;
            pin.CreatedAt      = DateTime.Now;
            pin.LastModifiedAt = DateTime.Now;
            pin.DeletedAt      = model.DeletedAt;
            pin.Active         = model.Active;

            db.PinCodes.Add(pin);

            int customerId = int.Parse(model.CustomerName);

            if (customerId > 0)
            {
                Customers cus = db.Customers.Find(customerId);
                pin.Id_Customer = cus.Id_Customer;
            }

            ViewBag.CustomerName = new SelectList((from c in db.Customers select new { Id_Customer = c.Id_Customer, CustomerName = c.CustomerName }), "Id_Customer", "CustomerName", null);

            int contractorId = int.Parse(model.CompanyName);

            if (contractorId > 0)
            {
                Contractors con = db.Contractors.Find(contractorId);
                pin.Id_Contractor = con.Id_Contractor;
            }



            int employeeId = int.Parse(model.FirstName);

            if (employeeId > 0)
            {
                Employees emp = db.Employees.Find(employeeId);
                pin.Id_Employee = emp.Id_Employee;
            }

            int employLastId = int.Parse(model.LastName);

            if (employLastId > 0)
            {
                Employees emp = db.Employees.Find(employLastId);
                pin.Id_Employee = emp.Id_Employee;
            }

            try
            {
                db.SaveChanges();
            }

            catch (Exception ex)
            {
            }

            return(RedirectToAction("Index"));
        }//create