Ejemplo n.º 1
0
        public IActionResult BadgeDelete(string id)
        {
            ObjectId oId = new ObjectId(id);

            var   earnerBadge = earnerBadgeDetails.DeleteMany <EarnerBadgeDetails>(e => e.BadgeId == oId);
            Badge badg        = badgeCollection.Find(e => e.BadgeId
                                                     == oId).FirstOrDefault();

            SolrBadgeModel sbdg = new SolrBadgeModel(badg);

            _solr.Delete(sbdg);
            _solr.Commit();
            var badge = badgeCollection.DeleteOne <Badge>(e => e.BadgeId == oId);         //To delete


            if (badge.IsAcknowledged)
            {
                TempData["Message"] = "Employee deleted successfully!";
            }
            else
            {
                TempData["Message"] = "Error while deleting Employee!";
            }
            return(RedirectToAction("Issuers"));
        }
Ejemplo n.º 2
0
        public IActionResult BadgeEdit(string Select, string id, Badge badge)
        {
            if (ModelState.IsValid)
            {
                double d = Math.Ceiling(badge.ExpiryDuration);
                switch (Select)
                {
                case "Days":
                {
                    badge.ExpiryDuration = d;
                }
                break;

                case "Weeks":
                {
                    badge.ExpiryDuration = d * 7;
                }
                break;

                case "Months":
                {
                    badge.ExpiryDuration = d * 30;
                }
                break;

                case "Years":
                {
                    badge.ExpiryDuration = d * 365;
                }
                break;
                }


                string webRootPath = _hostEnvironment.WebRootPath;
                var    files       = HttpContext.Request.Form.Files;

                ObjectId oId = new ObjectId(id);

                Badge badges = badgeCollection.Find(e => e.BadgeId
                                                    == oId).FirstOrDefault();

                if (files.Count > 0)
                {
                    string fileName   = Guid.NewGuid().ToString();
                    var    uploads    = Path.Combine(webRootPath, @"images/badges");
                    var    extenstion = Path.GetExtension(files[0].FileName);

                    if (badge.ImageUrl != null)
                    {
                        //this is an edit and we need to remove old image
                        var imagePath = Path.Combine(webRootPath, badge.ImageUrl.TrimStart('\\'));
                        if (System.IO.File.Exists(imagePath))
                        {
                            System.IO.File.Delete(imagePath);
                        }
                    }
                    using (var filesStreams = new FileStream(Path.Combine(uploads, fileName + extenstion), FileMode.Create))
                    {
                        files[0].CopyTo(filesStreams);
                    }
                    badge.ImageUrl = @"\images\badges\" + fileName + extenstion;
                }
                else
                {
                    //update when they do not change the image
                    if (badge.BadgeId != null)
                    {
                        badge.ImageUrl = badges.ImageUrl;
                    }
                }

                var filter = Builders <Badge> .Filter.Eq("BadgeId", oId);

                var updateDef = Builders <Badge> .Update.
                                Set("BadgeName", badge.BadgeName);

                updateDef = updateDef.Set("ImageUrl", badge.ImageUrl);
                updateDef = updateDef.Set("EarningCriteriaDescription", badge.EarningCriteriaDescription);
                updateDef = updateDef.Set("ExpiryDuration", badge.ExpiryDuration);

                var   result = badgeCollection.UpdateOne(filter, updateDef);        //to update
                Badge badg   = badgeCollection.Find(e => e.BadgeId
                                                    == oId).FirstOrDefault();
                SolrBadgeModel solrBadg = new SolrBadgeModel(badg);
                //solrBadg.BadgeId = b.BadgeId.ToString();
                _solr.Add(solrBadg);
                _solr.Commit();
                return(RedirectToAction("ViewBadge", new { id = id }));
            }

            return(View());
        }
Ejemplo n.º 3
0
        public IActionResult Badge(string Select, Badge issuerBadge)
        {
            var claimsIdentity = (ClaimsIdentity)User.Identity;
            /*var claim = claimsIdentity.FindFirst(ClaimTypes.Email);*/
            var      claim              = claimsIdentity.Claims.ToArray();
            var      email              = claim[1].Value;
            var      userid             = User.Claims.FirstOrDefault(c => c.Type == AppUtility.UserId).Value; //claim[3].Value;
            var      issuer             = collection.Find(FilterDefinition <Issuers> .Empty).ToList();
            var      userSpecificIssuer = issuer.Where(e => e.UserId == new ObjectId(userid)).FirstOrDefault();
            ObjectId iid = userSpecificIssuer.IssuerId;

            if (ModelState.IsValid)
            {
                double d = Math.Ceiling(issuerBadge.ExpiryDuration);
                switch (Select)
                {
                case "Days":
                {
                    issuerBadge.ExpiryDuration = d;
                }
                break;

                case "Weeks":
                {
                    issuerBadge.ExpiryDuration = d * 7;
                }
                break;

                case "Months":
                {
                    issuerBadge.ExpiryDuration = d * 30;
                }
                break;

                case "Years":
                {
                    issuerBadge.ExpiryDuration = d * 365;
                }
                break;
                }

                string webRootPath = _hostEnvironment.WebRootPath;
                var    files       = HttpContext.Request.Form.Files;
                if (files.Count > 0)
                {
                    string fileName   = Guid.NewGuid().ToString();
                    var    uploads    = Path.Combine(webRootPath, @"Images\badges");
                    var    extenstion = Path.GetExtension(files[0].FileName);


                    using (var filesStreams = new FileStream(Path.Combine(uploads, fileName + extenstion), FileMode.Create))
                    {
                        files[0].CopyTo(filesStreams);
                    }



                    issuerBadge.ImageUrl = @"/images/badges/" + fileName + extenstion;
                }

                DateTime today = DateTime.Now;

                Badge b = new Badge()
                {
                    IssuerId                   = userSpecificIssuer.IssuerId,
                    BadgeName                  = issuerBadge.BadgeName,
                    ImageUrl                   = issuerBadge.ImageUrl,
                    ExpiryDuration             = issuerBadge.ExpiryDuration,
                    EarningCriteriaDescription = issuerBadge.EarningCriteriaDescription,
                    CreatedDate                = today,
                    FacebookId                 = issuerBadge.FacebookId,
                    CreatedBy                  = userSpecificIssuer.Name
                };
                badgeCollection.InsertOne(b);
                SolrBadgeModel solrBadg = new SolrBadgeModel(b);
                //solrBadg.BadgeId = b.BadgeId.ToString();
                _solr.Add(solrBadg);
                _solr.Commit();
                return(RedirectToAction("Issuers"));
            }

            return(View());
        }