コード例 #1
0
        public ActionResult AddTaxiPrice([FromBody] TaxiPrice taxiPrice)
        {
            var identitiy = HttpContext.User.Identity as ClaimsIdentity;
            var userId    = Convert.ToInt64(identitiy.Name);

            taxiPrice.UserId = userId;
            try{
                return(Ok(_userService.AddTaxiPrice(taxiPrice)));
            }catch (Exception e) {
                return(BadRequest(e.Message));
            }
        }
コード例 #2
0
        public ActionResult UpdateTaxiprice([FromBody] TaxiPrice taxiPrice)
        {
            var identitiy = HttpContext.User.Identity as ClaimsIdentity;
            var userId    = Convert.ToInt64(identitiy.Name);

            taxiPrice.UserId = userId;
            try{
                return(Ok(_userService.UpdateTaxiPrice(taxiPrice)));
            }catch (AccessViolationException e) {
                return(StatusCode((int)HttpStatusCode.Forbidden, e.Message));
            }catch (ArgumentNullException e) {
                return(StatusCode((int)HttpStatusCode.NotFound, e.Message));
            }catch (Exception e) {
                return(BadRequest(e.Message));
            }
        }
コード例 #3
0
        public TaxiPrice UpdateTaxiPrice(TaxiPrice taxiPrice)
        {
            var _taxiPrice = _context.TaxiPrices.Find(taxiPrice.TaxiPriceId);

            if (_taxiPrice == null)
            {
                throw new ArgumentNullException("TaxiPrice Id does not exist!");
            }
            if (_taxiPrice.UserId != taxiPrice.UserId)
            {
                throw new AccessViolationException("You are not allowed to change this!");
            }
            _taxiPrice.PricePerHour  = taxiPrice.PricePerHour;
            _taxiPrice.PricePerUnit  = taxiPrice.PricePerUnit;
            _taxiPrice.SpecialPrice  = taxiPrice.SpecialPrice;
            _taxiPrice.StartingPrice = taxiPrice.StartingPrice;
            try{
                _context.TaxiPrices.Update(_taxiPrice);
                _context.SaveChanges();
                return(_taxiPrice);
            }catch (Exception e) {
                throw e;
            }
        }
コード例 #4
0
 public TaxiPrice AddTaxiPrice(TaxiPrice taxiPrice)
 {
     _context.TaxiPrices.Add(taxiPrice);
     _context.SaveChanges();
     return(taxiPrice);
 }