Ejemplo n.º 1
0
 public PurchasingClerkRouteDTO Map(PurchasingClerkRoute route)
 {
     if (route == null) return null;
     return Mapper.Map<PurchasingClerkRoute, PurchasingClerkRouteDTO>(route);
 }
Ejemplo n.º 2
0
        private List<PurchasingClerkRoute> GetRoutesAssigned(PurchasingClerk purchasingClerk)
        {
            using (var c = NestedContainer)
            {
                var assignedRouteItems = new List<PurchasingClerkRoute>();
                foreach (VMRouteItem item in AssignedRoutesList)
                {
                    PurchasingClerkRoute pcrItem = null;
                    var existing = _assignedRoutes.FirstOrDefault(n => n.Route.Id == item.Route.Id && n.PurchasingClerkRef.Id == purchasingClerk.Id);

                    pcrItem = new PurchasingClerkRoute(Guid.NewGuid())
                                  {
                                      Id = existing == null ? Guid.NewGuid() : existing.Id,
                                      Route = item.Route,
                                      _Status = EntityStatus.Active,
                                      PurchasingClerkRef = new CostCentreRef {Id = purchasingClerk.Id}
                                  };

                    assignedRouteItems.Add(pcrItem);
                    AuditLogEntry = string.Format("Assigned Route: {0}; To Costcentre: {1};", item.Route.Name,
                                                  purchasingClerk.Id);
                    Using<IAuditLogWFManager>(c).AuditLogEntry("User Administration", AuditLogEntry);
                }

                return assignedRouteItems;
            }
        }
Ejemplo n.º 3
0
 PurchasingClerkRouteItem Map(PurchasingClerkRoute pcRoute)
 {
     PurchasingClerkRouteItem mapped = new PurchasingClerkRouteItem
                                           {
                                               MasterId = pcRoute.Id,
                                               PurchasingClerkCostCentreId = pcRoute.PurchasingClerkRef.Id,
                                               RouteId = pcRoute.Route.Id,
                                               StatusId = (int) EntityStatus.Active,
                                           };
     return mapped;
 }
Ejemplo n.º 4
0
 protected Guid AddPurchasingClerkRoute(Guid hubId, Guid purchasingClerkId, Guid routeId)
 {
     CostCentre costcenterHub = _costCentreRepository.GetById(hubId);
     CostCentre costcenterPurchasingClerk = _costCentreRepository.GetById(purchasingClerkId);
     Route route = _routeRepository.GetById(routeId);
     PurchasingClerkRoute pcr = new PurchasingClerkRoute(Guid.NewGuid())
     {
         PurchasingClerkRef = new CostCentreRef { Id = costcenterPurchasingClerk.Id },
         Route = route
     };
     pcr._SetStatus(EntityStatus.Active);
     Guid id = _purchasingClerkRouteRepository.Save(pcr);
     return id;
 }
        public HttpResponseMessage PurchasingClerkRouteAdd(List<PurchasingClerkRouteItem> items)
        {
            var response = new ResponseBool { Success = false };
            PurchasingClerkRoute pcr = null;
            try
            {
                foreach (var item in items)
                {
                    var route = _routeRepository.GetById(item.RouteId);
                    pcr = new PurchasingClerkRoute(item.MasterId)
                    {
                        PurchasingClerkRef = new CostCentreRef { Id = item.PurchasingClerkCostCentreId },
                        Route = route
                    };

                    pcr._SetStatus(EntityStatus.Active);
                    _purchasingClerkRouteRepository.Save(pcr);
                    
                    _routeRepository.Save(route);
                }
                response.Success = true;
                response.ErrorInfo = "Successfully added purchasing clerk route.";
            }
            catch (Exception ex) //any other
            {
                response.ErrorInfo = "Error: An error occurred when creating or updating purchasing clerk route.";
                _log.Error("Error: An error occurred when creating or updating the purchasing clerk route.", ex);
            }

            return Request.CreateResponse(HttpStatusCode.OK, response);
        }
        public HttpResponseMessage PurchasingClerkAdd(PurchasingClerkItem purchasingClerkItem)
        {
            var response = new ResponseBool { Success = false };
            using (TransactionScope scope = TransactionUtils.CreateTransactionScope())
            {
                try
                {
                    Route route = null;
                    var hub = _costCentreRepository.GetById(purchasingClerkItem.ParentCostCentreId);
                    var purchasingClerk = _costCentreFactory.CreateCostCentre(purchasingClerkItem.MasterId, CostCentreType.PurchasingClerk, hub)
                        as PurchasingClerk;
                    if (purchasingClerk == null) throw new NullReferenceException();
                    purchasingClerk.Name = purchasingClerkItem.Name;
                    purchasingClerk.CostCentreCode = purchasingClerkItem.CostCentreCode;
                    purchasingClerk.User = new User(purchasingClerkItem.UserItem.MasterId)
                                               {
                                                   CostCentre = purchasingClerkItem.MasterId,
                                                   Username = purchasingClerkItem.UserItem.Username,
                                                   Password = purchasingClerkItem.UserItem.Password,
                                                   PIN = purchasingClerkItem.UserItem.PIN,
                                                   Mobile = purchasingClerkItem.UserItem.Mobile,
                                                   UserType = (UserType) purchasingClerkItem.UserItem.UserType,
                                                   TillNumber = purchasingClerkItem.UserItem.TillNumber,
                                               };
                    var query = new QueryPurchasingClerkRoute();
                    query.ShowInactive = true;
                    var existingAssignedRoutes = _purchasingClerkRouteRepository.Query(query)
                        .Where(n => n.PurchasingClerkRef.Id == purchasingClerkItem.MasterId);

                    //var existingAssignedRoutes = _purchasingClerkRouteRepository.GetAll(true)
                    //    .Where(n => n.PurchasingClerkRef.Id == purchasingClerkItem.MasterId);
                    var deletedRouteAssignments = existingAssignedRoutes
                        .Where(n => purchasingClerkItem.PurchasingClerkRouteItems.Select(x => x.RouteId).All(x => x != n.Route.Id));
                    foreach (var item in purchasingClerkItem.PurchasingClerkRouteItems)
                    {
                        route = _routeRepository.GetById(item.RouteId);
                        if(existingAssignedRoutes.Any(p=>p.Route==route))
                        {
                            continue;
                        }
                        var pcr = new PurchasingClerkRoute(item.MasterId)
                                                       {
                                                           Route = route,
                                                           PurchasingClerkRef = new CostCentreRef {Id = purchasingClerkItem.MasterId}
                                                       };
                        //_routeRepository.Save(route);
                        purchasingClerk.PurchasingClerkRoutes.Add(pcr);
                    }

                    foreach (var item in deletedRouteAssignments)
                    {
                        _purchasingClerkRouteRepository.SetAsDeleted(item);
                    }

                    purchasingClerk._SetStatus(EntityStatus.Active);
                    _purchasingClerkRepository.Save(purchasingClerk);

                    response.Success = true;
                    response.ErrorInfo = "Successfully added purchasing clerk.";
                    scope.Complete();
                }
                catch (DomainValidationException dve)
                {
                    string errorMsg = dve.ValidationResults.Results.Aggregate("Error: Invalid fields.\n",
                                                                              (current, msg) =>
                                                                              current +
                                                                              ("\t- " + msg.ErrorMessage + "\n"));
                    response.ErrorInfo = errorMsg;
                    _log.Error(errorMsg, dve);
                }
                catch (Exception ex) //any other
                {
                    response.ErrorInfo = "Error: An error occurred when creating or updating purchasing clerk.";
                    _log.Error("Error: An error occurred when creating or updating the purchasing clerk.", ex);
                }
            }
            return Request.CreateResponse(HttpStatusCode.OK, response);

        }