Exemple #1
0
        public ecvOperationStatus DeleteVendor(int vendorId)
        {
            vendorServiceStatus = new ecvOperationStatus();

            if (vendorId < 0)
            {
                vendorServiceStatus.operationStatus  = ecvOperationStatus.OperationStatus.Error;
                vendorServiceStatus.OperationMessage = "Invalid vendor id!";

                return(vendorServiceStatus);
            }

            var vendor = privateGetVendorById(vendorId); //--before marking vendor as deleted check it is exist in database

            if (vendor == null)
            {
                vendorServiceStatus.operationStatus  = ecvOperationStatus.OperationStatus.Error;
                vendorServiceStatus.OperationMessage = "Vendor not found while deleting!";

                return(vendorServiceStatus);
            }

            //--Before marking vendor as deleted should it check Business and Validation rules?

            //--Mark Vendor as deleted
            _unitOfWork.vendorRepository.markAsDeleted(vendorId);


            int intCompleteState = 0;

            intCompleteState = _unitOfWork.Complete();

            if (intCompleteState > 0)
            {
                // When successfull
                vendorServiceStatus.operationStatus  = OperationStatus.Success;
                vendorServiceStatus.OperationMessage = "";
            }
            else
            {
                vendorServiceStatus.operationStatus  = OperationStatus.Error;
                vendorServiceStatus.OperationMessage = _unitOfWork.ecvError;
            }

            return(vendorServiceStatus);
        }
Exemple #2
0
        public ecvOperationStatus DeleteManufacturer(int manufacturerId)
        {
            //throw new NotImplementedException();
            manufacturerServiceStatus = new ecvOperationStatus();

            if (manufacturerId < 0)
            {
                manufacturerServiceStatus.operationStatus  = ecvOperationStatus.OperationStatus.Error;
                manufacturerServiceStatus.OperationMessage = "Invalid manufacturer id!";

                return(manufacturerServiceStatus);
            }

            var manufacturer = privateGetManufacturerById(manufacturerId); //--before marking manufacturer as deleted check it is exist in database

            if (manufacturer == null)
            {
                manufacturerServiceStatus.operationStatus  = ecvOperationStatus.OperationStatus.Error;
                manufacturerServiceStatus.OperationMessage = "Manufacturer not found while deleting!";

                return(manufacturerServiceStatus);
            }

            //--Before marking Manufacturer as deleted should it check Business and Validation rules?

            //--Mark Manufacturer as deleted
            _unitOfWork.manufacturerRepository.markAsDeleted(manufacturerId);

            int intCompleteState = 0;

            intCompleteState = _unitOfWork.Complete();

            if (intCompleteState > 0)
            {
                // When successfull
                manufacturerServiceStatus.operationStatus  = OperationStatus.Success;
                manufacturerServiceStatus.OperationMessage = "";
            }
            else
            {
                manufacturerServiceStatus.operationStatus  = OperationStatus.Error;
                manufacturerServiceStatus.OperationMessage = _unitOfWork.ecvError;
            }

            return(manufacturerServiceStatus);
        }
Exemple #3
0
        public ecvOperationStatus SaveVendor(VendorDTO vendorDto)
        {
            Vendor vendor = new Vendor();

            vendorServiceStatus = new ecvOperationStatus();

            if (vendorDto.Id > 0)                                        //Record to update
            {
                vendor = _unitOfWork.vendorRepository.Get(vendorDto.Id); // privateGetVendorById(vendorDto.Id); //Get vendor entity from database
                if (vendor == null)
                {
                    vendorServiceStatus.operationStatus  = ecvOperationStatus.OperationStatus.Error;
                    vendorServiceStatus.OperationMessage = "Vendor not found while updating!";

                    return(vendorServiceStatus);
                }
                vendorDto.UpdatedOnUtc = DateTime.Now;
            }
            else // Record to add new
            {
                vendorDto.CreatedOnUtc = DateTime.Now;
                vendorDto.UpdatedOnUtc = DateTime.Now;

                _unitOfWork.vendorRepository.Add(vendor); //Create new vendor
            }

            //--Check business and validation rules
            bavrIssues = new List <ecvRuleViolation>();
            bavrIssues = processBAVRules(vendorDto);

            if (bavrIssues.Count() > 0)
            {
                vendorServiceStatus.operationStatus  = OperationStatus.Error;
                vendorServiceStatus.OperationMessage = "Business and validation rules violation!";
                vendorServiceStatus.ecvRuleViolation = bavrIssues;

                return(vendorServiceStatus);
            }

            //--Once business and validatin rules are passed copy values from DTO to VendorEntity.
            //--Prepare Vendor Model
            var vendorMapper = new ecvMapper <VendorDTO, Vendor>();

            vendorMapper.MapObject(vendorDto, vendor); //--Directly mapping object

            int intCompleteState = 0;

            intCompleteState = _unitOfWork.Complete();

            if (intCompleteState > 0)
            {
                // When successfully save record
                vendorServiceStatus.operationStatus  = OperationStatus.Success;
                vendorServiceStatus.OperationMessage = "";
            }
            else
            {
                vendorServiceStatus.operationStatus = OperationStatus.Error;
                if (!string.IsNullOrEmpty(_unitOfWork.ecvError))
                {
                    vendorServiceStatus.OperationMessage = _unitOfWork.ecvError;
                }
                else
                {
                    vendorServiceStatus.OperationMessage = "Error, unexpected error occured cannot save vendor record!";
                }
            }

            return(vendorServiceStatus);
        }// End of -- public void SaveVendor(VendorDTO vendorDto)