Example #1
0
        /*protected int AddUser(string Username, string password, string mobile, string pin, int costCenter, UserType usertype)
        {
            User usr = new User(Guid.NewGuid())
            {
                Username = Username,
                Password = password,
                Mobile = mobile,
                PIN = pin,
                UserType = usertype,
                CostCentre = costCenter


            };
            return _userRepository.Save(usr);
        }*/

        protected Guid CreateSalemanRoute(Guid distributorid, Guid salemanwarehouseid, Guid routeId)
        {
            CostCentre costcenterDistibutor = _costCentreRepository.GetById(distributorid);
            CostCentre costcenterDistibutorSaleman = _costCentreRepository.GetById(salemanwarehouseid);
            Route route = _routeRepository.GetById(routeId);
            SalesmanRoute sr = new SalesmanRoute(Guid.NewGuid())
            {
                DistributorSalesmanRef = new CostCentreRef { Id = costcenterDistibutorSaleman.Id },
                Route = route
            };
            sr._SetStatus(EntityStatus.Active);
            Guid id = _salesmanRouteRepository.Save(sr);
            return id;
        }
 public SalesmanRouteDTO Map(SalesmanRoute salesmanRoute)
 {
     if (salesmanRoute == null) return null;
     return Mapper.Map<SalesmanRoute, SalesmanRouteDTO>(salesmanRoute);
 }
        public HttpResponseMessage SalesmanRoutesUpdate(List<DistributorSalesmanRouteItem> routes)
        {
            var response = new ResponseBool { Success = false };
            try
            {
                foreach (DistributorSalesmanRouteItem item in routes)
                {

                    SalesmanRoute sr = new SalesmanRoute(item.MasterId)
                    {
                        DistributorSalesmanRef = new CostCentreRef { Id = item.CostCentreMasterId },
                        Route = _routeRepository.GetById(item.RouteMasterId),
                    };

                    _salesmanRouteRepository.Save(sr);
                    _log.Info(String.Format("Salesman {0} assigned to Route {1} ", item.CostCentreMasterId, item.RouteMasterId));
                }
                response.Success = true;
                response.ErrorInfo = "Successfully saved.";
            }
            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)
            {
                response.ErrorInfo = "Failed to assign Route(s) to a salesman.\nCause: "+ex.Message;
                _log.Error("Failed to assign Route(s) to a salesman ", ex);
            }
            return Request.CreateResponse(HttpStatusCode.OK, response);
        }