Example #1
0
        public async Task <IActionResult> ComponentDelete(PM_ComponentAjax model)
        {
            var result = new MessageReport(false, "Có lỗi xảy ra");

            try
            {
                var objComponent = await _PM_ComponentService.GetById(model.ComponentId);

                //Xóa component
                result = await _PM_ComponentService.Delete(model.ComponentId);

                if (result.isSuccess)
                {
                    //Xóa work ăn theo
                    await _PM_WorkService.DeleteByComponentId(model.ComponentId);

                    //
                    RemoveSchedule(objComponent);

                    //
                    _ReminderService.RemoveSchedule(model.ComponentId, "project");
                }
            }
            catch (Exception ex)
            {
                result = new MessageReport(false, ex.Message);
            }

            return(Json(result));
        }
Example #2
0
        public async Task <IActionResult> ComponentMComplete(PM_ComponentAjax model)
        {
            //
            var result = await _PM_ComponentService.MComplete(model.ComponentId);

            if (result.isSuccess == true)
            {
                await _PM_WorkService.MCompleteByComponentId(model.ComponentId);
            }

            return(Json(result));
        }
Example #3
0
        public async Task <IActionResult> ComponentParent(PM_ComponentAjax model)
        {
            var data = await _PM_ComponentService.GetById(model.ComponentId);

            return(Json(data));
        }
Example #4
0
        public async Task <IActionResult> ComponentSubmit(PM_ComponentAjax model)
        {
            var result = new MessageReport(false, "Có lỗi xảy ra");

            try
            {
                //Kiểm tra đã điền
                if (string.IsNullOrWhiteSpace(model.Code))
                {
                    result = new MessageReport(false, "Mã component không được để trống");
                    return(Json(result));
                }

                if (string.IsNullOrWhiteSpace(model.Title))
                {
                    result = new MessageReport(false, "Tên component không được để trống");
                    return(Json(result));
                }

                //Kiểm tra có tồn tại
                var existed = await _PM_ComponentService.GetById(model.ComponentId);

                if (existed == null)
                {
                    //Kiểm tra
                    var existedCodeInProject = await _PM_ComponentService.GetByCode(model.ProjectId, model.Code);

                    if (existedCodeInProject != null)
                    {
                        result = new MessageReport(false, "Mã hiệu đã tồn tại trong dự án");
                        return(Json(result));
                    }

                    //Thêm mới
                    existed = new PM_Component()
                    {
                        Code        = model.Code,
                        DateCreated = DateTime.Now,
                        DateEnd     = Convert.ToDateTime(model.DateEnd),
                        DateStart   = Convert.ToDateTime(model.DateStart),
                        Description = model.Description,
                        Id          = model.ComponentId,
                        Label       = "",
                        Note        = model.Note,
                        ParentId    = model.ParentId,
                        ProjectId   = model.ProjectId,
                        Status      = Convert.ToInt32(model.Status),
                        Title       = model.Title
                    };

                    result = await _PM_ComponentService.Create(existed);

                    if (result.isSuccess)
                    {
                        RegisterSchedule(existed);
                    }
                }
                else
                {
                    //Kiểm tra
                    var existedCodeInProject = await _PM_ComponentService.GetByCode(model.ProjectId, model.Code);

                    if (existedCodeInProject != null && existedCodeInProject.Id != model.ComponentId)
                    {
                        result = new MessageReport(false, "Mã hiệu đã tồn tại trong dự án");
                        return(Json(result));
                    }

                    //Cập nhật
                    existed.Note        = model.Note;
                    existed.ParentId    = model.ParentId;
                    existed.Status      = Convert.ToInt32(model.Status);
                    existed.Title       = model.Title;
                    existed.Description = model.Description;
                    existed.DateEnd     = Convert.ToDateTime(model.DateEnd);
                    existed.DateStart   = Convert.ToDateTime(model.DateStart);

                    result = await _PM_ComponentService.Update(existed);

                    if (result.isSuccess)
                    {
                        ReRegisterSchedule(existed);
                    }
                }
            }
            catch (Exception ex)
            {
                result = new MessageReport(false, ex.Message);
            }

            return(Json(result));
        }