Exemplo n.º 1
0
        public async ValueTask <IActionResult> Post([FromBody] SponsorBase model)
        {
            if (ModelState.IsValid)
            {
                var checker = await _repo.Item().Where(c => c.Name == model.Name).FirstOrDefaultAsync();

                if (checker != null)
                {
                    return(BadRequest(new ErrorDTO {
                        Message = "Sponsor already exists"
                    }));
                }
                Sponsor sponsor = model.Convert <SponsorBase, Sponsor>(_mapper);
                (bool succeeded, Sponsor addedSponsor, string error) = await _repo.Add(sponsor);

                if (succeeded)
                {
                    return(Ok(addedSponsor.Convert <Sponsor, SponsorBase>(_mapper)));
                }
                return(BadRequest(new ErrorDTO {
                    Message = error
                }));
            }
            return(BadRequest(new ErrorDTO {
                Errors = ModelState.Values.SelectMany(e => e.Errors).ToList()
            }));
        }
 public void DeleteSponsor(SponsorBase sponsor)
 {
     Requires.NotNull(sponsor);
     Requires.PropertyNotNegative(sponsor, "SponsorId");
     using (var context = DataContext.Instance())
     {
         var rep = context.GetRepository <SponsorBase>();
         rep.Delete(sponsor);
     }
 }
 public void UpdateSponsor(SponsorBase sponsor, int userId)
 {
     Requires.NotNull(sponsor);
     Requires.PropertyNotNegative(sponsor, "SponsorId");
     sponsor.LastModifiedByUserID = userId;
     sponsor.LastModifiedOnDate   = DateTime.Now;
     using (var context = DataContext.Instance())
     {
         var rep = context.GetRepository <SponsorBase>();
         rep.Update(sponsor);
     }
 }
 public int AddSponsor(ref SponsorBase sponsor, int userId)
 {
     Requires.NotNull(sponsor);
     sponsor.CreatedByUserID      = userId;
     sponsor.CreatedOnDate        = DateTime.Now;
     sponsor.LastModifiedByUserID = userId;
     sponsor.LastModifiedOnDate   = DateTime.Now;
     using (var context = DataContext.Instance())
     {
         var rep = context.GetRepository <SponsorBase>();
         rep.Insert(sponsor);
     }
     return(sponsor.SponsorId);
 }
Exemplo n.º 5
0
        public async ValueTask <IActionResult> Get(int id, bool projects = false)
        {
            Sponsor sponsor = null;

            if (!projects)
            {
                sponsor = await _repo.Item()
                          .Where(c => c.Id == id)
                          .FirstOrDefaultAsync();

                if (sponsor != null)
                {
                    SponsorBase model = sponsor.Convert <Sponsor, SponsorBase>(_mapper);
                    return(Ok(model));
                }
            }
            else
            {
                sponsor = await _repo.Item()
                          .Where(c => c.Id == id)
                          .Include(c => c.Projects)
                          .ThenInclude(p => p.Comments)
                          .FirstOrDefaultAsync();

                if (sponsor != null)
                {
                    SponsorDTO        model = sponsor.ConvertToDTO(_mapper);
                    SponsorProjectDTO dto   = new SponsorProjectDTO
                    {
                        Sponsor = model,
                        Total   = sponsor.Projects.Count()
                    };
                    return(Ok(dto));
                }
            }
            return(NotFound(new ErrorDTO {
                Message = "Item not found"
            }));
        }
Exemplo n.º 6
0
        public async ValueTask <IActionResult> Put([FromBody] SponsorBase model)
        {
            if (ModelState.IsValid)
            {
                if (model.Id != 0)
                {
                    Sponsor sponsor = model.Convert <SponsorBase, Sponsor>(_mapper);
                    (bool succeeded, Sponsor updatedSponsor, string error) = await _repo.Update(sponsor, model.Id);

                    if (succeeded)
                    {
                        return(Ok(updatedSponsor.Convert <Sponsor, SponsorBase>(_mapper)));
                    }
                    return(NotFound(new ErrorDTO {
                        Message = error
                    }));
                }
            }
            return(BadRequest(new ErrorDTO {
                Errors = ModelState.Values.SelectMany(e => e.Errors).ToList()
            }));
        }
Exemplo n.º 7
0
        public ActionResult Edit(SponsorBase sponsor, int conferenceId, HttpPostedFileBase image)
        {
            sponsor.ConferenceId = conferenceId;
            sponsor.Name         = sponsor.Name.Trim();
            sponsor.Url          = sponsor.Url.TrimSafeNull();
            var previousRecord = _repository.GetSponsor(sponsor.SponsorId);

            if (previousRecord == null)
            {
                _repository.AddSponsor(ref sponsor, User.UserID);
            }
            else
            {
                sponsor.CreatedOnDate   = previousRecord.CreatedOnDate;
                sponsor.CreatedByUserID = previousRecord.CreatedByUserID;
                _repository.UpdateSponsor(sponsor, User.UserID);
            }
            if (image != null)
            {
                sponsor.SaveLogo(PortalSettings, image.InputStream, System.IO.Path.GetExtension(image.FileName));
            }
            return(ReturnRoute("Sponsor", "Index", "ConferenceId=" + conferenceId.ToString()));
        }