Exemplo n.º 1
0
        public async Task<IHttpActionResult> Puthd(short id, Hd hd)
        {
            if (!ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }

            if (id != hd.Id)
            {
                return BadRequest();
            }
            
            try
            {
                await _repository.Update(hd);
            }
            catch (DbUpdateConcurrencyException msgDbUpdateConcurrencyException)
            {
                return InternalServerError(msgDbUpdateConcurrencyException);
            }
            catch (KeyNotFoundException)
            {
                return NotFound();
            }

            return StatusCode(HttpStatusCode.NoContent);
        }
Exemplo n.º 2
0
        public async Task<bool> Update(Hd item)
        {
            /*{
                "Name":"??",
                "Code":"??",
                "HdIdUpline" : "??"
            }*/

            //check IdExists
            var header = await IdExist(item.Id);
            
            //check Upline invalid
            if (item.HdIdUpline != null && item.HdIdUpline != 0)
            {
                var up = await IdExist(item.HdIdUpline.Value);
            }

            header.Name = item.Name;
            header.Code = item.Code;
            header.HdIdUpline = item.HdIdUpline;

            _db.Entry(header).State = EntityState.Modified;
            try
            {
                await _db.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException exception)
            {
                throw new DbUpdateConcurrencyException(exception.Message);
            }
            
            return true;
        }
Exemplo n.º 3
0
        public async Task<Hd> Add(Hd item)
        {
            /*{
                "Name":"??",
                "Code":"??",
                "HdIdUpline" : "??"
            }*/
            if (item.HdIdUpline != null && item.HdIdUpline != 0)
            {
                var up = await IdExist(item.HdIdUpline.Value);
            }

            var randResult = await RandHd();//random hd.value 3 char before add
            var newHd = new Hd
            {
                Name = item.Name,
                Code = item.Code,
                HdIdUpline = item.HdIdUpline,
                Value = randResult,
                TableName = "_" + randResult//use hd.value to create tableName "_xxx"
            };
            
            //create table backup in mysql ***
            //createBackUp(newHd.TableName);

            newHd = _db.Hds.Add(newHd);
            try
            {
                await _db.SaveChangesAsync();
                return newHd;
            }
            catch (DbUpdateConcurrencyException exception)
            {
                throw new DbUpdateConcurrencyException(exception.Message);
            }
            
        }
Exemplo n.º 4
0
        public async Task<IHttpActionResult> Posthd(Hd hd)
        {
            if (!ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }

            try
            {
                var header = await _repository.Add(hd);
                return CreatedAtRoute("DefaultApi", new { id = header.Id }, header);
            }
            catch (DbUpdateException msgDbUpdateException)
            {
                return InternalServerError(msgDbUpdateException);
            }
        }