Ejemplo n.º 1
0
        private async Task <Dictionary <string, int> > BulkSaveSites(IEnumerable <SiteDTO> allSites, IEnumerable <JobUploadModel> recs, Action <SiteDTO> onNewSiteCreated)
        {
            var comparer        = StringComparer.InvariantCultureIgnoreCase;
            var sitesBySiteName = new Dictionary <string, int>(comparer);

            foreach (var rec in recs.Select(z => z.SiteName.Trim()).Distinct())
            {
                var matchedSite = await SaveForMatchingField(allSites,
                                                             matchCriteria : (site, field) => site.SiteName.Trim().Equals(field, StringComparison.InvariantCultureIgnoreCase),
                                                             factory : async(field) =>
                {
                    var site = new SiteDTO()
                    {
                        SiteID = await _sitesRepository.Create(new SiteDTO()
                        {
                            SiteName = field
                        }),
                        SiteName = field
                    };
                    onNewSiteCreated(site);
                    return(site);
                },
                                                             field : rec);

                sitesBySiteName.TryAdd(matchedSite.SiteName.Trim(), matchedSite.SiteID);
            }
            return(sitesBySiteName);
        }
Ejemplo n.º 2
0
 public ActionResult Create(SiteDTO client)
 {
     try
     {
         siteService.Create(client);
         NotificationsController.AddNotification(this.User.SafeUserName(), $"{client.SiteName} has been created.");
         return(RedirectToAction(nameof(Create)));
     }
     catch
     {
         return(View());
     }
 }