public ActionResult UpdateEmployee(EmployeeModel data)
        {
            if (data == null)
            {
                return(Jsend(JsendResult <List <ValidationFailure> > .Error("Employee data can't be null")));
            }
            var validator = new EmployeeValidator();
            ValidationResult validateResult = validator.Validate(data);

            if (validateResult.IsValid)
            {
                try
                {
                    var result = RequestHelper.MakePostWebRequest <EmployeeModel, Jsend <EmployeeModel> >(
                        $"{apiDomain}/api/Employee", data, "PUT");
                    return(Jsend(result));
                }
                catch (WebException ex)
                {
                    Console.WriteLine(ex);
                    return(Jsend(JsendResult.Error("更新員工發生錯誤")));
                }
            }
            List <ValidationFailure> failures = validateResult.Errors.ToList();

            return(Jsend(JsendResult <List <ValidationFailure> > .Fail(failures)));
        }
Пример #2
0
        public ActionResult UpdateCompany(CompanyModel data)
        {
            if (data == null)
            {
                return(Jsend(JsendResult <List <ValidationFailure> > .Error("Company data can't be null")));
            }
            var validator = new CompanyValidator();
            ValidationResult validateResult = validator.Validate(data);

            if (validateResult.IsValid)
            {
                try
                {
                    var result = RequestHelper.MakePostWebRequest <CompanyModel, Jsend <CompanyModel> >(
                        $"{apiDomain}/api/Company", data, "PUT");
                    return(Jsend(result));
                }
                catch (WebException ex)
                {
                    Console.WriteLine(ex);
                    return(Jsend(JsendResult.Error("Add Company occured error")));
                }
            }
            List <ValidationFailure> failures = validateResult.Errors.ToList();

            return(Jsend(JsendResult <List <ValidationFailure> > .Fail(failures)));
        }
Пример #3
0
        public ActionResult AddProduct(ProductModel data)
        {
            if (data == null)
            {
                return(Jsend(JsendResult <List <ValidationFailure> > .Error("Product data can't be null")));
            }
            var validator = new ProductValidator();
            ValidationResult validateResult = validator.Validate(data);

            if (validateResult.IsValid)
            {
                try
                {
                    var result = RequestHelper.MakePostWebRequest <ProductModel, Jsend <ProductModel> >(
                        $"{apiDomain}/api/Product", data);
                    return(Jsend(result));
                }
                catch (WebException ex)
                {
                    Console.WriteLine(ex);
                    return(Jsend(JsendResult.Error("新增產品發生錯誤")));
                }
            }
            List <ValidationFailure> failures = validateResult.Errors.ToList();

            return(Jsend(JsendResult <List <ValidationFailure> > .Fail(failures)));
        }
Пример #4
0
        public Jsend <List <ValidationFailure> > AddProduct(ProductModel data)
        {
            if (data == null)
            {
                return(JsendResult <List <ValidationFailure> > .Error("Product data can't be null"));
            }

            var validator = new ProductValidator();
            ValidationResult validateResult = validator.Validate(data);

            if (validateResult.IsValid)
            {
                try
                {
                    _uow.ProductTRepository.Add(new ProductT
                    {
                        CompanyID   = data.CompanyID,
                        ProductName = data.ProductName,
                        ProductType = data.ProductType,
                        Price       = data.Price,
                        Unit        = data.Unit
                    });
                    _uow.Commit();
                    return(JsendResult <List <ValidationFailure> > .Success());
                }
                catch (SqlException ex)
                {
                    _logger.Error(ex);
                    return(JsendResult <List <ValidationFailure> > .Error("Insert Product occured error"));
                }
            }
            List <ValidationFailure> failures = validateResult.Errors.ToList();

            return(JsendResult <List <ValidationFailure> > .Fail(failures));
        }
Пример #5
0
        public Jsend <List <ValidationFailure> > InsertUpdateEmployee(EmployeeModel data)
        {
            if (data == null)
            {
                return(JsendResult <List <ValidationFailure> > .Error("Employee data can't be null"));
            }
            var validator = new EmployeeValidator();
            ValidationResult validateResult = validator.Validate(data);

            if (validateResult.IsValid)
            {
                try
                {
                    var result = _uow.EmployeeTRepository.FindByID(data.EmployeeID);
                    if (result == null)
                    {
                        _uow.EmployeeTRepository.Add(new EmployeeT
                        {
                            EmployeeName     = data.EmployeeName,
                            EmployeePosition = data.EmployeePosition,
                            EmployeePhone    = data.EmployeePhone,
                            Email            = data.Email,
                            BirthdayDate     = data.BirthdayDate,
                            SignInDate       = data.SignInDate,
                            ResignedDate     = data.ResignedDate,
                            IsResigned       = data.IsResigned,
                            CompanyID        = data.CompanyID
                        });
                    }
                    else
                    {
                        _uow.EmployeeTRepository.Update(new EmployeeT
                        {
                            EmployeeID       = data.EmployeeID,
                            EmployeeName     = data.EmployeeName,
                            EmployeePosition = data.EmployeePosition,
                            EmployeePhone    = data.EmployeePhone,
                            Email            = data.Email,
                            BirthdayDate     = data.BirthdayDate,
                            SignInDate       = data.SignInDate,
                            ResignedDate     = data.ResignedDate,
                            IsResigned       = data.IsResigned,
                            Salary           = data.Salary,
                        });
                    }
                    _uow.Commit();
                }
                catch (SqlException ex)
                {
                    _logger.Error(ex);
                    return(JsendResult <List <ValidationFailure> > .Error("InsertUpdateEmployee() InsertUpdate data occured error"));
                }
                return(JsendResult <List <ValidationFailure> > .Success());
            }

            List <ValidationFailure> failures = validateResult.Errors.ToList();

            return(JsendResult <List <ValidationFailure> > .Fail(failures));
        }
Пример #6
0
        public Jsend <List <ValidationFailure> > InsertUpdateCompany(CompanyModel data)
        {
            if (data == null)
            {
                return(JsendResult <List <ValidationFailure> > .Error("Company data can't be null"));
            }

            var validator = new CompanyValidator();
            ValidationResult validateResult = validator.Validate(data);

            if (validateResult.IsValid)
            {
                try
                {
                    var result = _uow.CompanyTRepository.FindByID(data.CompanyID);
                    if (result == null)
                    {
                        _uow.CompanyTRepository.Add(
                            new CompanyT
                        {
                            CompanyName = data.CompanyName,
                            CompanyCode = data.CompanyCode,
                            TaxID       = data.TaxID,
                            Phone       = data.Phone,
                            Owner       = data.Owner,
                            WebsiteURL  = data.WebsiteURL,
                            Address     = data.Address
                        });
                    }
                    else
                    {
                        _uow.CompanyTRepository.Update(
                            new CompanyT
                        {
                            CompanyID   = data.CompanyID,
                            CompanyName = data.CompanyName,
                            CompanyCode = data.CompanyCode,
                            TaxID       = data.TaxID,
                            Phone       = data.Phone,
                            Owner       = data.Owner,
                            WebsiteURL  = data.WebsiteURL,
                            Address     = data.Address
                        });
                    }
                    _uow.Commit();
                }
                catch (SqlException ex)
                {
                    _logger.Error(ex);
                    return(JsendResult <List <ValidationFailure> > .Error("Queay data occured error"));
                }

                return(JsendResult <List <ValidationFailure> > .Success());
            }
            List <ValidationFailure> failures = validateResult.Errors.ToList();


            return(JsendResult <List <ValidationFailure> > .Fail(failures));
        }
Пример #7
0
        public Jsend <List <ValidationFailure> > AddCompany(CompanyModel data)
        {
            if (data == null)
            {
                return(JsendResult <List <ValidationFailure> > .Error("Company data can't be null"));
            }

            var checkNameUnique = _uow.CompanyTRepository.FindByName(data.CompanyName);

            if (checkNameUnique != null)
            {
                return(JsendResult <List <ValidationFailure> > .Error("CompanyName has already had"));
            }

            var validator = new CompanyValidator();
            ValidationResult validateResult = validator.Validate(data);

            if (validateResult.IsValid)
            {
                try
                {
                    _uow.CompanyTRepository.Add(
                        new CompanyT
                    {
                        CompanyName = data.CompanyName,
                        CompanyCode = data.CompanyCode,
                        TaxID       = data.TaxID,
                        Phone       = data.Phone,
                        Owner       = data.Owner,
                        WebsiteURL  = data.WebsiteURL,
                        Address     = data.Address
                    });
                    _uow.Commit();
                }
                catch (SqlException ex)
                {
                    _logger.Error(ex);
                    return(JsendResult <List <ValidationFailure> > .Error("Insert data error"));
                }

                return(JsendResult <List <ValidationFailure> > .Success());
            }
            List <ValidationFailure> failures = validateResult.Errors.ToList();


            return(JsendResult <List <ValidationFailure> > .Fail(failures));
        }