Exemplo n.º 1
0
        public bool Create(string departmentName, out string message)
        {
            bool result = false;

            message = String.Empty;

            try
            {
                if (String.IsNullOrWhiteSpace(departmentName))
                {
                    message = "Department Name is required.";
                    return(result);
                }

                Department department = new Department()
                {
                    Name = departmentName,
                };
                _context.Departments.Add(department);
                _context.SaveChanges();
                result = true;
            }
            catch (Exception error)
            {
                message = error.Message;
                result  = false;
            }

            return(result);
        }
        public Discount CreateDiscount(string type, decimal value, int discountType, int status)
        {
            Discount discount = null;

            try
            {
                if (String.IsNullOrWhiteSpace(type))
                {
                    throw new ArgumentException("Type Is Required");
                }

                if (!Enum.IsDefined(typeof(DiscountType), discountType))
                {
                    throw new InvalidCastException("Invalid Discount Type (1 - Percentage, 2 - Fixed)");
                }
                DiscountType discountTypeSelected = (DiscountType)discountType;

                if (discountTypeSelected == DiscountType.Percentage)
                {
                    if (value < 0 || value > 100)
                    {
                        throw new ArgumentException("Percentage must be between 1 to 100");
                    }
                }
                else
                {
                    if (value < 100)
                    {
                        throw new ArgumentException("Minimum amount that can be set is 100.");
                    }
                }

                if (!Enum.IsDefined(typeof(DiscountStatus), status))
                {
                    throw new InvalidCastException("Invalid Discount Status (1 - Active, 2 - Inactive)");
                }
                DiscountStatus discountStatus = (DiscountStatus)status;

                discount = new Discount()
                {
                    Status       = discountStatus,
                    DateCreated  = DateTime.Now,
                    Value        = value,
                    Type         = type,
                    DiscountType = discountTypeSelected,
                };

                _context.Discounts.Add(discount);
                _context.SaveChanges();
            }
            catch (Exception err)
            {
                throw err;
            }

            return(discount);
        }
        public bool Create(string name, long departmentId, string profilePicName, out string message)
        {
            bool result = false;

            message = String.Empty;

            try
            {
                if (departmentId <= 0)
                {
                    message = "Invalid Department Id";
                    return(result);
                }

                if (String.IsNullOrWhiteSpace(name))
                {
                    message = "Name is required";
                    return(result);
                }

                Employee employee = new Employee()
                {
                    Name            = name,
                    Department      = _context.Departments.FirstOrDefault(x => x.Id == departmentId),
                    ProfileFileName = profilePicName,
                    DateJoining     = DateTime.Now
                };
                _context.Employees.Add(employee);
                _context.SaveChanges();
                result = true;
            }
            catch (Exception error)
            {
                message = error.Message;
                result  = false;
            }

            return(result);
        }
Exemplo n.º 4
0
        public Customer CreateCustomer(string fullname, int customerType)
        {
            Customer customer = null;

            try
            {
                if (String.IsNullOrWhiteSpace(fullname))
                {
                    throw new ArgumentException("Full Name Is Required");
                }

                if (customerType <= 0)
                {
                    throw new ArgumentException("Customer type is required when creating a customer");
                }

                if (!Enum.IsDefined(typeof(CustomerType), customerType))
                {
                    throw new InvalidCastException("Invalid Customer Type (1 - Normal, 2 - Employee, 3 - Affiliate)");
                }

                CustomerType customerTypeCast = (CustomerType)customerType;

                customer = new Customer()
                {
                    Fullname     = fullname,
                    CustomerType = customerTypeCast,
                    DateCreated  = DateTime.Now,
                };

                _context.Customers.Add(customer);
                _context.SaveChanges();
            }
            catch (Exception err)
            {
                throw err;
            }

            return(customer);
        }