Example #1
0
        public IHttpActionResult Put([FromODataUri] string key, CustomerCardAdministrationDataModel update)
        {
            //var customEx = new Exception("Hello I am testing Elmah", new NotSupportedException());
            //ErrorSignal.FromCurrentContext().Raise(customEx);
            //throw new Exception();

            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            if (key != update.Id)
            {
                return(BadRequest());
            }

            if (this.cutomerCards.GetById(update.Id) == null)
            {
                return(NotFound());
            }

            var dbModel = this.cutomerCards.GetById(update.Id);

            Mapper.Map <CustomerCardAdministrationDataModel, CustomerCard>(update, dbModel);
            this.cutomerCards.Update(dbModel);

            try
            {
                this.cutomerCards.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!CardExists(key))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(this.Updated(update));
        }
        public IHttpActionResult Post(CustomerCardAdministrationDataModel customerCards)
        {
            if (!ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }

            //customerCards.Id = Guid.NewGuid().ToString();
            var generatedId = GenerateRandomNumber(12);
            var existId = this.cutomerCards.All().Any(u => u.Id == generatedId);

            while (true)
            {
                if (!existId)
                {
                    customerCards.Id = generatedId;
                    break;
                }
                generatedId = GenerateRandomNumber(12);
                existId = this.cutomerCards.All().Any(u => u.Id == generatedId);
            }

            var dm = Mapper.Map<CustomerCard>(customerCards);

            this.cutomerCards.Add(dm);

            try

            {
                this.cutomerCards.SaveChanges();
            }
            catch (DbUpdateException)
            {
                if (CardExists(customerCards.Id))
                {
                    return Conflict();
                }
                throw;
            }

            return Created(customerCards);
        }
Example #3
0
        public IHttpActionResult Post(CustomerCardAdministrationDataModel customerCards)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            //customerCards.Id = Guid.NewGuid().ToString();
            var generatedId = GenerateRandomNumber(12);
            var existId     = this.cutomerCards.All().Any(u => u.Id == generatedId);

            while (true)
            {
                if (!existId)
                {
                    customerCards.Id = generatedId;
                    break;
                }
                generatedId = GenerateRandomNumber(12);
                existId     = this.cutomerCards.All().Any(u => u.Id == generatedId);
            }

            var dm = Mapper.Map <CustomerCard>(customerCards);

            this.cutomerCards.Add(dm);

            try

            {
                this.cutomerCards.SaveChanges();
            }
            catch (DbUpdateException)
            {
                if (CardExists(customerCards.Id))
                {
                    return(Conflict());
                }
                throw;
            }

            return(Created(customerCards));
        }
        public IHttpActionResult Put([FromODataUri] string key, CustomerCardAdministrationDataModel update)
        {
            //var customEx = new Exception("Hello I am testing Elmah", new NotSupportedException());
            //ErrorSignal.FromCurrentContext().Raise(customEx);
            //throw new Exception();

            if (!ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }
            if (key != update.Id)
            {
                return BadRequest();
            }

            if (this.cutomerCards.GetById(update.Id) == null)
            {
                return NotFound();
            }

            var dbModel = this.cutomerCards.GetById(update.Id);
            Mapper.Map<CustomerCardAdministrationDataModel, CustomerCard>(update, dbModel);
            this.cutomerCards.Update(dbModel);

            try
            {
                this.cutomerCards.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!CardExists(key))
                {
                    return NotFound();
                }
                else
                {
                    throw;
                }
            }

            return this.Updated(update);
        }