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);
        }
Example #2
0
        public ActionResult Index()
        {
            using (var contextoBd = new AgroContext())
            {
                var Tipocultivo = (from sd in contextoBd.TipoCultivo
                                   select new
                {
                    sd.CultivoId,
                    sd.NombreCultivo
                }).ToList();
                var listacultivo = new SelectList(Tipocultivo.OrderBy(o => o.CultivoId), "CultivoId", "NombreCultivo");
                ViewData["TipoCultivo"] = listacultivo;

                var Tiposuelo = (from sd in contextoBd.TipoSuelo
                                 select new
                {
                    sd.TipoSueloId,
                    sd.NombreTipoSuelo
                }).ToList();
                var listaSuelo = new SelectList(Tiposuelo.OrderBy(o => o.TipoSueloId), "TipoSueloId", "NombreTipoSuelo");
                ViewData["TipoSuelo"] = listaSuelo;
            }

            var query = db.Produccion
                        .Include("TipoClima")
                        .Include("TipoSuelo")
                        .Include("Cultivo");

            return(View(query.ToList()));
        }
Example #3
0
        /// <param name="context"></param>
        /// <param name="username"></param>
        /// <returns>Returns User with given username</returns>
        public static User GetUser(AgroContext context, string username)
        {
            if (string.IsNullOrWhiteSpace(username))
            {
                throw new ArgumentException();
            }

            return(context.Users.FirstOrDefault(x => x.Username == username));
        }
Example #4
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);
        }
Example #5
0
        /// <param name="context"></param>
        /// <param name="username"></param>
        /// <param name="password"></param>
        /// <returns>Returns true if the given username and password are matching and found</returns>
        public static bool IsValid(AgroContext context, string username, string password)
        {
            if (string.IsNullOrWhiteSpace(username) || string.IsNullOrWhiteSpace(password))
            {
                throw new ArgumentException();
            }

            string hash = GetEncodedHash(password, "123");

            return(context.Users.FirstOrDefault(x => x.Username == username && x.PasswordEncrypted == hash) != null);
        }
Example #6
0
        /// <param name="context"></param>
        /// <param name="username"></param>
        /// <returns>Returns true if username is found</returns>
        public static bool Exist(AgroContext context, string username)
        {
            if (string.IsNullOrWhiteSpace(username))
            {
                throw new ArgumentException();
            }

            int count = context.Users.Count(x => x.Username == username);

            return(count == 1);
        }
Example #7
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!");
            }
        }
Example #8
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);
            }
        }
        public static object GetTimesheet(AgroContext context, int employeeId, int assignmentId)
        {
            return(context.Timesheets.Where(x => x.AssignmentId == assignmentId && x.UserId == employeeId)
                   .Include(x => x.Records)
                   .Include(x => x.Assignment)
                   .ThenInclude(x => x.Customer)
                   .Select(x => new
            {
                x.TimesheetId,
                x.Records,
                x.IsVerified,
                User = new { x.User.Name },

                Assignment = new
                {
                    x.Assignment.Customer,
                    x.Assignment.Date,
                    x.Assignment.Location,
                    x.Assignment.Description,
                    x.Assignment.Employees
                }
            }).First());
        }
Example #10
0
 public UserController(AgroContext context)
 {
     _context = context;
 }
Example #11
0
 /// <param name="context"></param>
 /// <param name="archived"></param>
 /// <returns>Returns list with all users, if archived is true it returns all archived users</returns>
 public static IEnumerable <User> GetUsers(AgroContext context, bool archived = false)
 {
     return(context.Users.Where(x => x.IsArchived == archived));
 }
 public static Assignment GetAssignment(AgroContext context, int assignmentId)
 {
     return(context.Assignments.FirstOrDefault(x => x.AssignmentId == assignmentId));
 }
Example #13
0
 public static object AddCustomer(AgroContext context, Customer customer)
 {
     context.Customers.Add(customer);
     context.SaveChanges();
     return(true);
 }
Example #14
0
 public CustomerController(AgroContext context)
 {
     _context = context;
 }
Example #15
0
 public HomeController(AgroContext context)
 {
     _context = context;
 }
 public AssignmentController(AgroContext context)
 {
     _context = context;
 }
 public static object GetTimesheet(AgroContext context, HttpContext httpContext, int assignmentId)
 {
     return(GetTimesheet(context, UserController.GetLoggedInUserId(httpContext), assignmentId));
 }
Example #18
0
 public TransactionRepository(AgroContext context)
 {
     _context = context;
 }
Example #19
0
 public TimesheetController(AgroContext context)
 {
     _context = context;
 }
Example #20
0
 public MachinesController(AgroContext context)
 {
     _context = context;
 }
Example #21
0
 /// <param name="context"></param>
 /// <param name="userId"></param>
 /// <returns>Returns User with given UserId</returns>
 public static User GetUser(AgroContext context, int userId)
 {
     return(context.Users.FirstOrDefault(x => x.UserId == userId));
 }
Example #22
0
 public static Customer GetCustomer(AgroContext context, int id)
 {
     return(context.Customers.First(x => x.CustomerId == id));
 }
Example #23
0
 /// <summary>
 /// Returns the user that is currently logged in
 /// </summary>
 /// <param name="dbContext"></param>
 /// <param name="httpContext"></param>
 /// <returns></returns>
 public static User GetUser(AgroContext dbContext, HttpContext httpContext)
 {
     return(GetUser(dbContext, GetLoggedInUserId(httpContext)));
 }
Example #24
0
 public AttachmentsController(AgroContext context)
 {
     _context = context;
 }
Example #25
0
 public AdminController(AgroContext context)
 {
     _context = context;
 }