Exemplo n.º 1
0
        public Invoice Create(Invoice invoice)
        {
            // validation
            if (_context.Invoices.Any(x => x.IID == invoice.IID))
            {
                throw new AppException("Invoice ID " + invoice.IID + " is already in use");
            }

            // Name of Invoice Owner based on Due Date
            if (_context.Invoices.Any(x => x.Invoice_Too + x.DueDate + x.DueDate == invoice.Invoice_Too + invoice.DueDate + invoice.ClientID))
            {
                throw new AppException("Bill " + invoice.Invoice_Too + invoice.DueDate + invoice.ClientID + " has already been made");
            }

            //InvoiceItems
            if (_context.Invoices.Any(x => x.InvoiceItems + x.ClientID + x.IID == invoice.InvoiceItems + invoice.ClientID + invoice.IID))
            {
                throw new AppException("Invoice Item " + invoice.InvoiceItems + invoice.ClientID + invoice.IID + " is already in use");
            }

            //InvoiceNotes
            if (_context.Invoices.Any(x => x.InvoiceNotes + x.ClientID + x.IID == invoice.InvoiceNotes + invoice.ClientID + invoice.IID))
            {
                throw new AppException("Invoice Notes " + invoice.InvoiceNotes + invoice.ClientID + invoice.IID + " for " + invoice.ClientID + invoice.IID + " is already in use");
            }


            _context.Invoices.Add(invoice);
            _context.SaveChanges();

            return(invoice);
        }
Exemplo n.º 2
0
        public Employee Create(Employee employee)
        {
            // validation
            if (_context.Employees.Any(x => x.EID == employee.EID))
            {
                throw new AppException("Employee ID " + employee.EID + " is already in use");
            }

            if (_context.Employees.Any(x => x.EmpFirstName + x.EmpLastName == employee.EmpFirstName + employee.EmpLastName))
            {
                throw new AppException("Employee Name " + employee.EmpFirstName + employee.EmpLastName + " is already in use");
            }

            if (_context.Employees.Any(x => x.EmpEmail == employee.EmpEmail))
            {
                throw new AppException("Employee Email " + employee.EmpEmail + " is already in use");
            }

            if (_context.Employees.Any(x => x.EmpPhone == employee.EmpPhone))
            {
                throw new AppException("Employee Phone " + employee.EmpPhone + " is already in use");
            }

            _context.Employees.Add(employee);
            _context.SaveChanges();

            return(employee);
        }
Exemplo n.º 3
0
        public Client Create(Client client)
        {
            // validation
            if (_context.Clients.Any(x => x.BusinessName == client.BusinessName))
            {
                throw new AppException("Business Name " + client.BusinessName + " is already in use");
            }

            // validation
            if (_context.Clients.Any(x => x.ClientID == client.ClientID))
            {
                throw new AppException("Client Ide " + client.ClientID + " is already in use");
            }

            _context.Clients.Add(client);
            _context.SaveChanges();

            return(client);
        }
Exemplo n.º 4
0
        public Calendar Create(Calendar calendar)
        {
            // validation
            if (_context.Calendars.Any(x => x.CalendarTitle == calendar.CalendarTitle))
            {
                throw new AppException("Calendar Title " + calendar.CalendarTitle + " is already in use");
            }

            // validation
            if (_context.Calendars.Any(x => x.CalendarID == calendar.CalendarID))
            {
                throw new AppException("Client Ide " + calendar.CalendarID + " is already in use");
            }

            _context.Calendars.Add(calendar);
            _context.SaveChanges();

            return(calendar);
        }
Exemplo n.º 5
0
        public Project Create(Project project)
        {
            // validation
            if (_context.Projects.Any(x => x.PID == project.PID))
            {
                throw new AppException("Project ID " + project.PID + " is already in use");
            }

            if (_context.Projects.Any(x => x.ProjectTitle == project.ProjectTitle))
            {
                throw new AppException("Project Title " + project.ProjectTitle + " is already in use");
            }

            if (_context.Projects.Any(x => x.ProjectNotes == project.ProjectNotes))
            {
                throw new AppException("Project Notes " + project.ProjectNotes + " is already in use");
            }

            if (_context.Projects.Any(x => x.DueDate == project.DueDate))
            {
                throw new AppException("Due Date " + project.DueDate + " has not changed");
            }

            if (_context.Projects.Any(x => x.ClientID == project.ClientID))
            {
                throw new AppException("Client ID " + project.ClientID + " has not changed");
            }

            if (_context.Projects.Any(x => x.EmpID == project.EmpID))
            {
                throw new AppException("Employee ID " + project.EmpID + " has not changed");
            }

            _context.Projects.Add(project);
            _context.SaveChanges();

            return(project);
        }
Exemplo n.º 6
0
        public Post Create(Post post)
        {
            // validation
            if (_context.Posts.Any(x => x.PostId == post.PostId))
            {
                throw new AppException("Post ID " + post.PostId + " is already in use");
            }

            if (_context.Posts.Any(x => x.Title == post.Title))
            {
                throw new AppException("Post Title " + post.Title + " is already in use");
            }

            if (_context.Posts.Any(x => x.Content == post.Content))
            {
                throw new AppException("Post Content " + post.Content + " is already in use");
            }

            _context.Posts.Add(post);
            _context.SaveChanges();

            return(post);
        }
Exemplo n.º 7
0
        public User Create(User user, string password)
        {
            // validation
            if (string.IsNullOrWhiteSpace(password))
            {
                throw new AppException("Password is required");
            }

            if (_context.Users.Any(x => x.Username == user.Username))
            {
                throw new AppException("Username " + user.Username + " is already taken");
            }

            byte[] passwordHash, passwordSalt;
            CreatePasswordHash(password, out passwordHash, out passwordSalt);

            user.PasswordHash = passwordHash;
            user.PasswordSalt = passwordSalt;

            _context.Users.Add(user);
            _context.SaveChanges();

            return(user);
        }