Example #1
0
        public bool DeleteAssignment(AssignmentViewModel model)
        {
            _log.InfoFormat("Method: DeleteAssignment. Model ID {0}", model.Id);
            var databaseAssignment = _repository.SearchFor <SageAssignment>(x => x.WorkOrder == model.WorkOrder).Single();
            var workOrder          = _repository.SearchFor <SageWorkOrder>(x => x.WorkOrder == model.WorkOrder).Single();
            var employee           = _repository.SearchFor <SageEmployee>(x => x.Employee == model.Employee).SingleOrDefault();
            var result             = _sageApiProxy.UnassignWorkOrders(model.WorkOrder);

            if (!result.IsSucceed)
            {
                _log.ErrorFormat("!result.IsSucceed. Error");
                return(false);
            }
            databaseAssignment.Employee   = "";
            databaseAssignment.EmployeeId = 0;
            databaseAssignment.Start      = "";
            databaseAssignment.End        = "";
            databaseAssignment.Color      = "";
            databaseAssignment.Customer   = "";
            databaseAssignment.Location   = "";
            _repository.Update(databaseAssignment);
            _log.InfoFormat("Deleted from repository: databaseAssignment ID {0}", databaseAssignment.Id);
            workOrder.Employee     = "";
            workOrder.ScheduleDate = null;
            workOrder.AssignmentId = databaseAssignment.Assignment;
            _repository.Update(workOrder);
            _log.InfoFormat("Repository update workorder. Name: {0}, Id: {1}", workOrder.Name, workOrder.Id);
            _notification.SendNotification(string.Format("Workorder {0} unassigned from {1}", workOrder.Name, employee.Name));
            _hub.DeleteAssigment(model);

            return(true);
        }