Example #1
0
        public override IHttpActionResult Post(Warehouse model)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var  featureWarehouseValue          = _featureProvider.GetEditionFeatureValue(model.TenantId, StaticFeature.Warehouse.Name);
            bool isReachedMaximumWarehouseCount =
                _service.IsReachedMaximumWarehouseCount(model.TenantId, Convert.ToInt32(featureWarehouseValue));

            if (isReachedMaximumWarehouseCount)
            {
                return(BadRequest("You already have added " + featureWarehouseValue + " warehouse. You can not add more warehouse with your current subscription."));
            }

            var isWarehouseNameExist = _service.IsWarehouseNameExist(model.Name, model.Id, ActionType.Put);

            if (isWarehouseNameExist)
            {
                return(BadRequest(model.Name + " warehouse name already exist."));
            }

            var isWarehouseCodeExist = _service.IsWarehouseCodeExist(model.Code, model.Id, ActionType.Put);

            if (isWarehouseCodeExist)
            {
                return(BadRequest(model.Name + " warehouse code already exist."));
            }

            if (string.IsNullOrWhiteSpace(model.Id))
            {
                model.Id = Guid.NewGuid().ToString();
            }
            model.Active = true;

            _service.AddAsTenant(model);

            return(Ok(model.Id));
        }
Example #2
0
        public override IHttpActionResult Post(Branch model)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var company = _companyService.GetById(model.CompanyId);

            model.TenantId = company.TenantId;

            var  featureBranchCount     = _featureProvider.GetEditionFeatureValue(model.TenantId, StaticFeature.Showroom.Name);
            bool isReachedMaximumBranch =
                _service.IsReachedMaximumBranchCount(model.TenantId, Convert.ToInt32(featureBranchCount));

            if (isReachedMaximumBranch)
            {
                return(BadRequest("You already have added " + featureBranchCount + " branch. You can not add more branch with your current subscription."));
            }

            if (model.Type == BranchType.HeadOffice)
            {
                bool isHeadOfficeBranchExist = _service.IsHeadOfficeExist(model.Type, model.Id, model.TenantId);
                if (isHeadOfficeBranchExist)
                {
                    return(BadRequest("Head office  branch type already exist. You can not add duplicate head office."));
                }
            }

            var isBranchExist = _service.IsBranchExist(model.Name, model.Id, model.TenantId);

            if (isBranchExist)
            {
                return(BadRequest(model.Name + " branch name already exist"));
            }


            if (string.IsNullOrWhiteSpace(model.LinkedWarehouseId))
            {
                var warehouseId = Guid.NewGuid().ToString();
                var warehouse   = new Warehouse
                {
                    Id         = warehouseId,
                    Code       = model.Code,
                    Name       = model.Name,
                    Address    = model.Address,
                    Created    = model.Created,
                    CreatedBy  = model.CreatedBy,
                    Modified   = model.Modified,
                    ModifiedBy = model.ModifiedBy,
                    Active     = true,
                    Type       = model.Type == BranchType.HeadOffice
                        ? WarehouseType.HeadOffice
                        : WarehouseType.Showroom,
                };


                if (IsSystemAdminUser() && model.IsHostAction)
                {
                    _warehouseService.CreateAsHost(warehouse);
                }
                else
                {
                    _warehouseService.AddAsTenant(warehouse);
                }

                model.LinkedWarehouseId = warehouseId;
            }

            if (string.IsNullOrWhiteSpace(model.Id))
            {
                model.Id = Guid.NewGuid().ToString();
            }
            model.Active = true;

            if (IsSystemAdminUser() && model.IsHostAction)
            {
                Service.CreateAsHost(model);
            }
            else
            {
                Service.AddAsTenant(model);
            }

            return(Ok(model.Id));
        }