Example #1
0
        public DeleteOperationGroupResponse DeleteOperationGroup(DeleteOperationGroupRequest request)
        {
            try
            {
                var OperationGroup = new KeyOperationGroup { Id = request.Id };
                DataContext.KeyOperationGroups.Attach(OperationGroup);
                DataContext.KeyOperationGroups.Remove(OperationGroup);
                DataContext.SaveChanges();

                return new DeleteOperationGroupResponse
                {
                    IsSuccess = true,
                    Message = "The Operation Group has been deleted successfully"
                };
            }
            catch(DbUpdateException exception)
            {
                return new DeleteOperationGroupResponse
                {
                    IsSuccess = false,
                    Message = exception.Message
                };
            }
        }
Example #2
0
        public UpdateOperationResponse UpdateOperation(UpdateOperationRequest request)
        {
            bool isKpiExisted =
                DataContext.KeyOperationConfigs.Include(x => x.Kpi).FirstOrDefault(x => x.Kpi.Id == request.KpiId) != null;
            if (request.Id == 0 && !isKpiExisted)
            {
                var operationConfig = new KeyOperationConfig();
                operationConfig.IsActive = request.IsActive.HasValue && request.IsActive.Value;
                operationConfig.Order = request.Order.HasValue ? request.Order.Value : 0;
                operationConfig.Kpi = DataContext.Kpis.Single(x => x.Id == request.KpiId);
                if (request.KeyOperationGroupId > 0)
                {
                    operationConfig.KeyOperationGroup =
                        DataContext.KeyOperationGroups.Single(x => x.Id == request.KeyOperationGroupId);
                }

                DataContext.KeyOperationConfigs.Add(operationConfig);
                DataContext.SaveChanges();
                return new UpdateOperationResponse
                {
                    IsSuccess = true,
                    Message = "Operation Config has been saved succesfully",
                    Id = operationConfig.Id
                };
            }
            else
            {
                var operationConfig = DataContext.KeyOperationConfigs
                    .Include(x => x.KeyOperationGroup)
                    .Single(x => x.Id == request.Id);
                if (request.IsActive.HasValue)
                {
                    operationConfig.IsActive = request.IsActive.Value;
                }

                if (request.Order.HasValue)
                {
                    operationConfig.Order = request.Order.Value;
                }

                if (request.KeyOperationGroupId != 0)
                {
                    var group = new KeyOperationGroup { Id = request.KeyOperationGroupId };
                    DataContext.KeyOperationGroups.Attach(group);
                    operationConfig.KeyOperationGroup = group;
                }

                DataContext.SaveChanges();
                return new UpdateOperationResponse
                {
                    IsSuccess = true,
                    Message = "Operation Config has been saved succesfully",
                    Id = operationConfig.Id
                };
            }
        }