示例#1
0
        public async Task <IActionResult> PutSponser([FromRoute] int id, [FromBody] Sponser sponser)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != sponser.id)
            {
                return(BadRequest());
            }

            _context.Entry(sponser).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!SponserExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
        public async Task <Sponser> UpdateSponser(int sponserId, Sponser sponser)
        {
            Sponser foundSponcer = await _dbContext.Sponsers.FindAsync(sponserId);

            if (foundSponcer == null)
            {
                return(null);
            }

            foundSponcer.DateOfBirth           = sponser.DateOfBirth;
            foundSponcer.EducationalLevel      = sponser.EducationalLevel;
            foundSponcer.FirstName             = sponser.FirstName;
            foundSponcer.Gender                = sponser.Gender;
            foundSponcer.ImageUrl              = sponser.ImageUrl;
            foundSponcer.MaritalStatus         = sponser.MaritalStatus;
            foundSponcer.MiddleNames           = sponser.MiddleNames;
            foundSponcer.Nationality           = sponser.Nationality;
            foundSponcer.Occupation            = sponser.Occupation;
            foundSponcer.PreferedCommunication = sponser.PreferedCommunication;
            foundSponcer.Surname               = sponser.Surname;

            _ = _dbContext.Sponsers.Update(foundSponcer);
            _ = await _dbContext.SaveChangesAsync();

            return(foundSponcer);
        }
        //[ValidateAntiForgeryToken]
        public ActionResult DeleteConfirmed(int id)
        {
            Sponser sponser = db.Sponsers.Find(id);

            db.Sponsers.Remove(sponser);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
        public async Task <Sponser> AddSponser(Sponser sponser)
        {
            _ = await _dbContext.Sponsers.AddAsync(sponser);

            _ = await _dbContext.SaveChangesAsync();

            return(sponser);
        }
 //[ValidateAntiForgeryToken]
 public ActionResult Edit([Bind(Include = "SponserID,FirstName,LastName,FlatNo,SponserDate,Amount,Details,CreatedDate")] Sponser sponser)
 {
     sponser.ModifiedDate = Common.GetCurrentDate();
     sponser.UserProfile  = db.Users.Find(User.Identity.GetUserId());
     if (ModelState.IsValid)
     {
         db.Entry(sponser).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(sponser));
 }
示例#6
0
        public async Task <IActionResult> PostSponser([FromBody] Sponser sponser)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            _context.Sponsers.Add(sponser);
            await _context.SaveChangesAsync();

            return(CreatedAtAction("GetSponser", new { id = sponser.id }, sponser));
        }
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            Sponser sponser = db.Sponsers.Find(id);

            if (sponser == null)
            {
                return(HttpNotFound());
            }
            return(View(sponser));
        }
        public async Task <Sponser> DeleteSponser(int sponserId)
        {
            Sponser foundSponser = await _dbContext.Sponsers.FindAsync(sponserId);

            if (foundSponser == null)
            {
                return(null);
            }

            _dbContext.Sponsers.Remove(foundSponser);
            _ = await _dbContext.SaveChangesAsync();

            return(foundSponser);
        }
        public async Task <Sponser> GetSponser(int sponserId)
        {
            if (await _dbContext.Sponsers.FindAsync(sponserId) == null)
            {
                return(null);
            }

            Sponser foundSponser = await _dbContext.Sponsers
                                   .Include(s => s.Contacts)
                                   .Include(s => s.Letters)
                                   .Include(s => s.Visits)
                                   .Include(s => s.VolunteeringActivities)
                                   .Where <Sponser>(s => s.PersonID == sponserId)
                                   .FirstAsync();

            return(foundSponser);
        }