Beispiel #1
0
        public async Task <int> UpdateMissionPhoto(PhotoUpdateDto updateObject, int photoId, string code)
        {
            var photo2bUpdated = await _context.MissionPhotos.FindAsync(photoId);

            photo2bUpdated.Category     = updateObject.Category;
            photo2bUpdated.ImageCaption = updateObject.Caption;
            photo2bUpdated.UploadedBy   = code;
            _context.MissionPhotos.Update(photo2bUpdated);
            var numberAffected = await _context.SaveChangesAsync();

            return(numberAffected);
        }
Beispiel #2
0
        public async Task <int> AddEvent(EventObj eventObj)
        {
            var evtObj = await _context.EventItems.AddAsync(eventObj);

            if (evtObj == null)
            {
                throw new Exception("The Event was not created.");
            }
            var numberAffected = await _context.SaveChangesAsync();

            return(numberAffected);
        }
        public async Task <bool> RateVideo(RatingsDto ratingsObject)
        {
            var video = await _context.MissionVideos.FindAsync(ratingsObject.VideoId);

            video.RatingsCount += 1;
            video.Rating        = ratingsObject.Rating / video.RatingsCount;
            _context.Update(video);
            var numbr = await _context.SaveChangesAsync();

            if (numbr.Equals(0))
            {
                return(false);
            }

            return(true);
        }
Beispiel #4
0
        public async Task <int> Add(MissionPhoto photo)
        {
            _context.Add(photo);
            var confrm = await _context.SaveChangesAsync();

            return(confrm);
        }
Beispiel #5
0
        public async Task <int> EditAnFaq(Faq changedFaq)
        {
            var faq = await _context.FaqItems.FirstOrDefaultAsync(f => f.FaqId == changedFaq.FaqId);

            if (faq != null)
            {
                faq.FaqAnswer   = changedFaq.FaqAnswer;
                faq.FaqQuestion = changedFaq.FaqQuestion;

                _context.FaqItems.Update(faq);
                var numEdited = await _context.SaveChangesAsync();

                return(numEdited);
            }

            return(0);
        }
        public async Task <int> DeleteUser(string email)
        {
            var user2Delete = _userManager.Users.FirstOrDefault(u => u.Email == email);

            if (user2Delete == null)
            {
                throw new Exception("No such user found");
            }
            _context.Users.Remove(user2Delete);
            var num = await _context.SaveChangesAsync();

            return(num);
        }
        public async Task <int> AddContribution(ContributionsPostDto contributionsObj)
        {
            var recordExists = await _context.Subscriptions
                               .AnyAsync(s => s.Name == contributionsObj.Month && s.Year == contributionsObj.Year && s.UserId == contributionsObj.UserId);

            if (recordExists == true)
            {
                throw new Exception("The contribution exists already.");
            }

            // Get the current year so as to filter only for current year
            var currentYear = DateTime.Now.ToString("yyyy");

            var memberTotal = await _context.Subscriptions
                              .Where(s => s.Year == contributionsObj.Year && s.UserId == contributionsObj.UserId)
                              .SumAsync(s => s.Amount);

            var newSubscription = new Subscription();

            newSubscription.Name        = contributionsObj.Month;
            newSubscription.Amount      = contributionsObj.Amount;
            newSubscription.DateEntered = contributionsObj.DateEntered;
            newSubscription.UserId      = contributionsObj.UserId;
            newSubscription.Year        = contributionsObj.Year;
            newSubscription.Total       = memberTotal + contributionsObj.Amount;

            bool includeThisMonth = true;

            if ((int)System.DateTime.Now.DayOfWeek < 15)
            {
                includeThisMonth = false;
            }

            newSubscription.UptoDate = await checkContributionStatus(contributionsObj.UserId, newSubscription.Total, includeThisMonth);

            if (!String.IsNullOrWhiteSpace(contributionsObj.Comment))
            {
                newSubscription.Comment = contributionsObj.Comment;
            }

            await _context.Subscriptions.AddAsync(newSubscription);

            var res = await _context.SaveChangesAsync();

            if (!res.Equals(1))
            {
                throw new Exception("No record was added for a new contribution");
            }
            return(res);
        }