コード例 #1
0
ファイル: ShipperController.cs プロジェクト: binhtv1997/Bus
        public ActionResult CreateShipper([FromBody] CreateShipperVM shipper)
        {
            var result = _shipperService.GetShippers(s => s.Phone == shipper.Phone);

            if (result.Count() > 0)
            {
                return(BadRequest("Phone Number Has Been Exist"));
            }
            var _Account = _shipperService.GetShippers(s => s.AccountId == shipper.AccountId);

            if (!_Account.Any())
            {
                var     newUser_Id = Guid.NewGuid();
                Account newAccount = new Account();
                newAccount.User_Id = newUser_Id.ToString();
                _accountService.CreateAccount(newAccount);
                _accountService.Save();
                Shipper newShipper = shipper.Adapt <Shipper>();
                newShipper.IsDelete  = false;
                newShipper.AccountId = newAccount.Id;
                _shipperService.CreateShipper(newShipper);
            }
            else
            {
                Shipper newShipper = shipper.Adapt <Shipper>();
                newShipper.IsDelete  = false;
                newShipper.AccountId = _Account.FirstOrDefault().Id;
                _shipperService.CreateShipper(newShipper);
            }
            _shipperService.Save();
            _hub.Clients.All.SendAsync("transferchartdata", "Hello");
            return(Ok(201));
        }
コード例 #2
0
        public ActionResult CreateShipper([FromBody] CreateShipperVM shipper)
        {
            var result = _shipperService.GetShippers(s => s.Phone == shipper.Phone);

            if (result.Count() > 0)
            {
                return(BadRequest("Phone Number Has Been Exist"));
            }
            Shipper newShipper = shipper.Adapt <Shipper>();

            newShipper.IsDelete = false;
            _shipperService.CreateShipper(newShipper);
            _shipperService.Save();
            return(Ok(200));
        }
コード例 #3
0
        public IActionResult SaveEntity(ShipperViewModel viewModel)
        {
            if (!ModelState.IsValid)
            {
                IEnumerable <ModelError> allErrors = ModelState.Values.SelectMany(n => n.Errors);
                return(new BadRequestObjectResult(allErrors));
            }
            else
            {
                if (viewModel.Id == 0)
                {
                    _shipperService.Add(viewModel);
                }
                else
                {
                    _shipperService.Update(viewModel);
                }
            }

            _shipperService.Save();

            return(new OkObjectResult(viewModel));
        }
コード例 #4
0
        public ActionResult DeleteAccount(Guid Id)
        {
            try
            {
                var result = _accountService.GetAccount(Id);
                if (result != null)
                {
                    if (_shipperService.GetShippers(s => s.AccountId == Id).Count() > 0)
                    {
                        var shipper = _shipperService.GetShippers(s => s.AccountId == Id).ToList();
                        _shipperService.DeleteShipper(shipper.FirstOrDefault());
                        _shipperService.Save();
                    }

                    if (_customerService.GetCustomers(c => c.AccountId == Id).Count() > 0)
                    {
                        var customer = _customerService.GetCustomers(s => s.AccountId == Id).ToList();
                        _customerService.DeleteCustomer(customer.FirstOrDefault());
                        _customerService.Save();
                    }

                    if (_storeService.GetStores(s => s.AccountId == Id).Count() > 0)
                    {
                        var store = _storeService.GetStores(s => s.AccountId == Id).ToList();

                        _storeService.DeleteStore(store.FirstOrDefault());
                        var listService = _serviceService.GetServices(s => s.StoreId == store[0].Id).ToList();
                        foreach (var item in listService)
                        {
                            _serviceService.DeleteService(item);
                        }
                        _serviceService.Save();
                        _storeService.Save();
                    }
                    _accountService.DeleteAccount(result);
                    _accountService.Save();
                    return(Ok(201));
                }
                return(NotFound());
            }
            catch (Exception)
            {
                return(BadRequest());
            }
        }