Beispiel #1
0
 public ActivityDocument Create(CostCentre hub, CostCentre clerk, CostCentre supplier, CommodityProducer commodityProducer, ActivityType activityType, Route route, Centre centre, Season season, string documentReference, Guid documentIssueCostCentreApplicationId, DateTime documentDate, DateTime activityDate, string description = "", string note = "")
 {
     Guid id = Guid.NewGuid();
     ActivityDocument doc = DocumentPrivateConstruct<ActivityDocument>(id);
    
     doc.DocumentDate = documentDate;
     doc.DocumentDateIssued = activityDate;
     doc.Description = description;
     doc.Hub = hub;
     doc.FieldClerk = clerk;
     doc.Supplier = supplier;
     doc.Producer = commodityProducer;
     doc.ActivityType = activityType;
     doc.Route = route;
     doc.Centre = centre;
     doc.DocumentReference = documentReference;
     doc.DocumentIssuerCostCentreApplicationId = documentIssueCostCentreApplicationId;
     doc.Hub = hub;
     doc.FieldClerk = clerk;
     doc.Supplier = supplier;
     doc.DocumentReference = documentReference;
     doc.ActivityDate = activityDate;
     doc.DocumentDateIssued = DateTime.Now;
     doc.Season = season;
     SetDefaultDates(doc);
     doc.EnableAddCommands();
     return doc;
 }
        private CentreViewModel Map(Centre centre)
        {
            CentreViewModel centreViewModel = new CentreViewModel();
            centreViewModel.Id = centre.Id;
            centreViewModel.Name = centre.Name;
            centreViewModel.Code = centre.Code;
            centreViewModel.Description = centre.Description;
            centreViewModel.IsActive = centre._Status == EntityStatus.Active ? true : false;
            centreViewModel.SelectedHubId = centre.Hub.Id;
            centreViewModel.SelectedHubName = centre.Hub.Name;
            centreViewModel.SelectedRouteId = centre.Route != null ? centre.Route.Id : Guid.Empty;
            centreViewModel.SelectedRouteName = centre.Route != null ? centre.Route.Name : "";

            if (centre.CenterType != null)
            {
                Guid typeId = centre.CenterType.Id;
                centreViewModel.CenterTypeId = _centreTypeRepository.GetById(typeId).Id;
                centreViewModel.CentreTypeName = _centreTypeRepository.GetById(typeId).Name;
            }

            return centreViewModel;
        }
 public CentreDTO Map(Centre centre)
 {
     if (centre == null) return null;
     var centreDto = Mapper.Map<Centre, CentreDTO>(centre);
     return centreDto;
 }
 public async Task<ResponseBool> CentreAddAsync(Centre centre)
 {
     ResponseBool _response = new ResponseBool { Success = false, ErrorInfo = "" };
     string url = string.Format("api/distributorservices/centreadd");
     var httpClient = setupHttpClient();
     httpClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
     try
     {
         var response = await httpClient.PostAsJsonAsync(url, centre);
         _response = await response.Content.ReadAsAsync<ResponseBool>();
     }
     catch (Exception ex)
     {
         _log.Error("Failed to update centre.\nCause:", ex);
     }
     return _response;
 }
 private void AssertCentre(Centre centre, Centre savedCentre)
 {
     Assert.AreEqual(centre.Name,savedCentre.Name);
     Assert.AreEqual(centre.Code,savedCentre.Code);
     Assert.AreEqual(centre.Description,savedCentre.Description);
     Assert.AreEqual(centre.CenterType.Code,savedCentre.CenterType.Code);
     Assert.AreEqual(centre.Route.Code,savedCentre.Route.Code);
     Assert.AreEqual(centre.Hub.Id, savedCentre.Hub.Id);
     Assert.AreEqual(centre._Status,EntityStatus.Active);
 }
        public void Save(CentreViewModel centreviewmodel)
        {
            if (centreviewmodel.SelectedRouteId == Guid.Empty)
                throw new Exception("Select a valid route.");

            Centre centre = new Centre(centreviewmodel.Id);
            centre.Code = centreviewmodel.Code;
            centre.Name = centreviewmodel.Name;
            centre.Description = centreviewmodel.Description;
            centre.CenterType = _centreTypeRepository.GetById(centreviewmodel.CenterTypeId);
            centre.Route = _routeRepository.GetById(centreviewmodel.SelectedRouteId);
            centre.Hub = _costCentreRepository.GetById(centreviewmodel.SelectedHubId) as Hub;

            _centreRepository.Save(centre);
        }
Beispiel #7
0
 public bool CheckAgriCentreIsUsed(Centre centre, EntityStatus intendedStatus)
 {
     var allocatedToCommodityProducers = _ctx.tblMasterDataAllocation
         .Where(n => n.AllocationType == (int) MasterDataAllocationType.CommodityProducerCentreAllocation &&
                     n.EntityBId == centre.Id)
         .Select(n => _ctx.tblCommodityProducer.FirstOrDefault(p => p.Id == n.EntityAId));
     if(intendedStatus == EntityStatus.Inactive)
     {
         if (allocatedToCommodityProducers.Any(n => n.IM_Status == (int)EntityStatus.Active))
             return true;
     }
     if (intendedStatus == EntityStatus.Deleted)
     {
         if (allocatedToCommodityProducers.Any(n => n.IM_Status == (int)EntityStatus.Inactive))
             return true;
     }
     return false;
 }
 protected Guid AddCentre(string name, string code, Guid ct, Guid hubId, Guid routeId)
 {
     Centre c = new Centre(Guid.NewGuid())
     {
         CenterType = _centreTypeRepository.GetById( ct),
         Name = name,
         Code = code,
         Description = "DEsc",
         _Status = EntityStatus.Active,
         Route = _routeRepository.GetById(routeId),
         Hub = _costCentreRepository.GetById(hubId) as Hub
     };
     return _centreRepository.Save(c);
 }
 protected override void LoadPage(Page page)
 {
     Guid centreId = PresentationUtility.ParseIdFromUrl(page.NavigationService.CurrentSource);
     using (var c = NestedContainer)
     {
         if (centreId == Guid.Empty)
         {
             Centre = new Centre(Guid.NewGuid());
             Centre.Hub = Using<ICostCentreRepository>(c).GetById(GetConfigParams().CostCentreId) as Hub;
             PageTitle = "Create Buying/Collection Centre";
         }
         else
         {
             var centre = Using<ICentreRepository>(c).GetById(centreId);
             Centre = centre.Clone<Centre>();
             PageTitle = "Edit Buying/Collection Centre";
         }
         Setup();
         if (Centre._Status != EntityStatus.New)
         {
             SelectedCentreType = CentreTypesList.FirstOrDefault(n => n.Id == Centre.CenterType.Id);
             SelectedRoute = RoutesList.FirstOrDefault(n => n != null && n.Id == Centre.Route.Id);
         }
     }
 }
        private VMCentreItem Map(Centre centre, int i)
        {
            VMCentreItem mapped = new VMCentreItem()
                                      {
                                          Centre = centre,
                                          RowNumber = i
                                      };
            if (centre._Status == EntityStatus.Active)
                mapped.HlkDeactivateContent = "Deactivate";
            else if (centre._Status == EntityStatus.Inactive)
                mapped.HlkDeactivateContent = "Activate";

            return mapped;
        }
        public HttpResponseMessage CentreAdd(Centre centre)
        {
            var response = new ResponseBool { Success = false };
            using (TransactionScope scope = TransactionUtils.CreateTransactionScope())
            {
                try
                {
                    _centreRepository.Save(centre);

                    response.Success = true;
                    response.ErrorInfo = "Centre successfully added.";
                    scope.Complete();
                }
                catch (DomainValidationException dve)
                {
                    string errorMsg = dve.ValidationResults.Results.Aggregate("Error: Invalid centre 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 saving the entity.\n" + ex.ToString();
                    _log.Error("Error: An error occurred when saving the entity.", ex);
                }
            }
            return Request.CreateResponse(HttpStatusCode.OK, response);
        }