public async Task <object> CreateOC(CreateOCViewModel oc)
        {
            try
            {
                if (oc.ID == 0)
                {
                    var item = _mapper.Map <Data.Models.OC>(oc);
                    item.Level = 1;

                    await _context.OCs.AddAsync(item);
                }
                else
                {
                    var item = await _context.OCs.FindAsync(oc.ID);

                    item.Name = oc.Name;
                }

                await _context.SaveChangesAsync();

                return(true);
            }
            catch (Exception ex)
            {
                return(false);
            }
        }
        public async Task <object> CreateOC(CreateOCViewModel oc)
        {
            try
            {
                if (oc.ID == 0)
                {
                    var item = _mapper.Map <CreateOCViewModel, OC>(oc);
                    item.Level = 1;

                    await _oCRepository.AddAsync(item);
                }
                else
                {
                    var item = await _oCRepository.FindByIdAsync(oc.ID);

                    item.Name = oc.Name;
                }

                await _unitOfWork.Commit();

                return(true);
            }
            catch (Exception ex)
            {
                return(false);
            }
        }
        public async Task <object> CreateSubOC(CreateOCViewModel oc)
        {
            var item = _mapper.Map <Data.Models.OC>(oc);

            //Level cha tang len 1 va gan parentid cho subtask
            var taskParent = _context.OCs.Find(item.ParentID);

            item.Level    = taskParent.Level + 1;
            item.ParentID = oc.ParentID;
            await _context.OCs.AddAsync(item);

            try
            {
                await _context.SaveChangesAsync();

                return(true);
            }
            catch (Exception)
            {
                return(false);
            }
        }
        public async Task <object> CreateSubOC(CreateOCViewModel oc)
        {
            var item = _mapper.Map <CreateOCViewModel, OC>(oc);

            //Level cha tang len 1 va gan parentid cho subtask
            var taskParent = await _oCRepository.FindByIdAsync(item.ParentID);

            item.Level    = taskParent.Level + 1;
            item.ParentID = oc.ParentID;
            await _oCRepository.AddAsync(item);

            try
            {
                await _unitOfWork.Commit();

                return(true);
            }
            catch (Exception)
            {
                return(false);
            }
        }
Exemple #5
0
 public async Task <IActionResult> CreateSubOC([FromBody] CreateOCViewModel oC)
 {
     return(Ok(await _ocService.CreateSubOC(oC)));
 }