Ejemplo n.º 1
0
        public ActionResult Create([Bind(Include = "ProduccionId,NombreProducto,Clima")] Produccion produccion)
        {
            if (ModelState.IsValid)
            {
                db.Produccion.Add(produccion);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(produccion));
        }
Ejemplo n.º 2
0
        public static object AddAssignment(AgroContext context, Assignment am)
        {
            if (am == null)
            {
                throw new ArgumentException("Assignment is null");
            }

            //am.Customer = CustomerController.GetCustomer(context, am.CustomerId);
            am.Timesheets = new List <Timesheet>();
            if (am.Employees != null)
            {
                foreach (User user in am.Employees)
                {
                    am.Timesheets.Add(new Timesheet()
                    {
                        UserId = user.UserId
                    });
                }
            }

            context.Assignments.Add(am);
            context.SaveChanges();

            return(true);
        }
Ejemplo n.º 3
0
        public static object EditCustomer(AgroContext context, Customer customer)
        {
            Customer c = GetCustomer(context, customer.CustomerId);

            c.Name    = customer.Name;
            c.Address = customer.Address;
            context.SaveChanges();
            return(true);
        }
Ejemplo n.º 4
0
        public bool AddTimeSheet([FromBody] Models.TimesheetRecord timesheet)
        {
            _context.TimesheetRecords.Add(timesheet);
            _context.SaveChanges();
            return(true);

            //using (MySqlConnection conn = await DatabaseConnection.GetConnection())
            //{
            //    int idTimesheet = -1;
            //    string query = "INSERT INTO Timesheet (timesheet.idTimesheet, timesheet.workType, timesheet.startTime, timesheet.endTime, timesheet.totalTime, timesheet.description) "
            //                + "VALUES (@0, @1, @2, @3, @4, @5); SELECT LAST_INSERT_ID()";
            //    using (MySqlDataReader reader = await MySqlHelper.ExecuteReaderAsync(conn, query,
            //        new MySqlParameter("@0", timesheet.IdTimesheet),
            //        new MySqlParameter("@1", timesheet.WorkType),
            //        new MySqlParameter("@2", timesheet.StartTime),
            //        new MySqlParameter("@3", timesheet.EndTime),
            //        new MySqlParameter("@4", timesheet.TotalTime),
            //        new MySqlParameter("@5", timesheet.Description)))
            //    {
            //        await reader.ReadAsync();
            //        idTimesheet = reader.GetInt32(0);
            //    }

            //    try
            //    {
            //        query = "INSERT INTO TimeSheetMachine (idTimesheet, idMachine) VALUES (@0, @1)";
            //        foreach (Machine machine in timesheet.Machines)
            //            await MySqlHelper.ExecuteNonQueryAsync(conn, query,
            //                new MySqlParameter("@0", idTimesheet),
            //                new MySqlParameter("@1", machine.IdMachine));

            //        query = "INSERT INTO TimeSheetAttachment (idTimesheet, idAttachment) VALUES (@0, @1)";
            //        foreach (Attachment attachment in timesheet.Attachments)
            //            await MySqlHelper.ExecuteNonQueryAsync(conn, query,
            //                new MySqlParameter("@0", idTimesheet),
            //                new MySqlParameter("@1", attachment.IdAttachment));

            //    }
            //    catch (Exception ex)
            //    {
            //        return false;
            //    }
            //    return true;
            //}
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Adds user to the database
        /// </summary>
        /// <param name="context"></param>
        /// <param name="user"></param>
        public static object AddUser(AgroContext context, User user)
        {
            user.Username          = user.Username.ToLower();
            user.PasswordEncrypted = GetEncodedHash(user.Password, "123");

            if (GetUser(context, user.Username) != null)
            {
                return("Gebruiker bestaat al!");
            }

            context.Users.Add(user);
            try
            {
                context.SaveChanges();
                return(true);
            }
            catch
            {
                return("Er is iets misgegaan!");
            }
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Edits the givin user with the data received
        /// </summary>
        /// <param name="context"></param>
        /// <param name="changedUser"></param>
        public static object EditUser(AgroContext context, User changedUser)
        {
            User user = GetUser(context, changedUser.UserId);

            user.Name     = changedUser.Name;
            user.Role     = changedUser.Role;
            user.Username = changedUser.Username.ToLower();

            if (changedUser.Password?.Length >= 3)
            {
                user.PasswordEncrypted = GetEncodedHash(changedUser.Password, "123");
            }

            try
            {
                context.SaveChanges();
                return(true);
            }
            catch (Exception ex)
            {
                return("Ër is iets misgegaan! " + ex.Message);
            }
        }
Ejemplo n.º 7
0
 public static object AddCustomer(AgroContext context, Customer customer)
 {
     context.Customers.Add(customer);
     context.SaveChanges();
     return(true);
 }
Ejemplo n.º 8
0
 public object ArchiveUser(int userId)
 {
     GetUser(_context, userId).IsArchived = true;
     _context.SaveChanges();
     return(true);
 }