Example #1
0
        public override void UpdateCharity(ICharity charityDTO)
        {
            Charity oldC = _store.Charities
                           .Include(x => x.CreatedBy)
                           .Include(x => x.UpdatedBy)
                           .Include(x => x.Locations)
                           .Single(x => x.Id == charityDTO.Id);

            _store.Entry(oldC).CurrentValues.SetValues(charityDTO);

            if (charityDTO.Category != null)
            {
                oldC.CategoryId = charityDTO.Category.Id;
            }

            if (charityDTO.CreatedBy != null)
            {
                oldC.CreatedById = charityDTO.CreatedBy.Id;
            }

            if (charityDTO.UpdatedBy != null)
            {
                oldC.UpdatedById = charityDTO.UpdatedBy.Id;
            }

            _store.SaveChanges();
        }
Example #2
0
        public override int CreateCharity(ICharity charityDTO)
        {
            if (_store.Charities.Any(x => x.Name == charityDTO.Name))
            {
                throw new ArgumentException(); //To-Do: Make custom exception for when duplicate names are found
            }
            Charity c = CharityFactory.CreateCharity(charityDTO);

            if (charityDTO.Category != null)
            {
                c.CategoryId = charityDTO.Category.Id;
            }
            if (charityDTO.CreatedBy != null)
            {
                c.CreatedById = charityDTO.CreatedBy.Id;
            }

            if (charityDTO.UpdatedBy != null)
            {
                c.UpdatedById = charityDTO.UpdatedBy.Id;
            }
            c = _store.Charities.Add(c);
            _store.SaveChanges();
            return(c.Id);
        }
Example #3
0
 public IHttpActionResult Post([FromBody] ICharity charity)
 {
     try
     {
         // TO-DO: replace with Created 201 response
         return(Ok(this.Service.CreateCharity(charity)));
     }
     catch (Exception e)
     {
         return(InternalServerError());
     }
 }
Example #4
0
 public IHttpActionResult Put(int id, [FromBody] ICharity charity)
 {
     try
     {
         this.Service.UpdateCharity(charity);
         return(StatusCode(HttpStatusCode.NoContent));
     }
     catch (InvalidOperationException e)
     {
         return(BadRequest());
     }
     catch (Exception e)
     {
         return(InternalServerError());
     }
 }
        public static Charity CreateCharity(ICharity charityDTO)
        {

            if (charityDTO == null) return null;

            return new Charity
            {
                Id = charityDTO.Id,
                Name = charityDTO.Name,
                ShortDescription = charityDTO.ShortDescription,
                ImageUrl = charityDTO.ImageUrl,
                Email = charityDTO.Email,
                PhoneNumber = charityDTO.PhoneNumber,
                WebsiteURL = charityDTO.WebsiteUrl,
                CreatedAt = charityDTO.CreatedAt,
                UpdatedAt = charityDTO.UpdatedAt,
                Locations = null
            };
        }
        public static Charity CreateCharity(ICharity charityDTO)
        {
            if (charityDTO == null)
            {
                return(null);
            }

            return(new Charity
            {
                Id = charityDTO.Id,
                Name = charityDTO.Name,
                ShortDescription = charityDTO.ShortDescription,
                ImageUrl = charityDTO.ImageUrl,
                Email = charityDTO.Email,
                PhoneNumber = charityDTO.PhoneNumber,
                WebsiteURL = charityDTO.WebsiteUrl,
                CreatedAt = charityDTO.CreatedAt,
                UpdatedAt = charityDTO.UpdatedAt,
                Locations = null
            });
        }
        public override int CreateCharity(ICharity charityDTO)
        {
            if (_store.Charities.Any(x => x.Name == charityDTO.Name))
                throw new ArgumentException(); //To-Do: Make custom exception for when duplicate names are found

            Charity c = CharityFactory.CreateCharity(charityDTO);
            if (charityDTO.Category != null)
            {
                c.CategoryId = charityDTO.Category.Id;
            }
            if (charityDTO.CreatedBy != null)
            {
                c.CreatedById = charityDTO.CreatedBy.Id;
            }

            if (charityDTO.UpdatedBy != null)
            {
                c.UpdatedById = charityDTO.UpdatedBy.Id;
            }
            c = _store.Charities.Add(c);
            _store.SaveChanges();
            return c.Id;
        }
 public virtual void UpdateCharity(ICharity charity)
 {
     _service.UpdateCharity(charity);
 }
 public virtual int CreateCharity(ICharity charity)
 {
     return _service.CreateCharity(charity);
 }
 public virtual void UpdateCharity(ICharity charity)
 {
     _service.UpdateCharity(charity);
 }
 public virtual int CreateCharity(ICharity charity)
 {
     return(_service.CreateCharity(charity));
 }
 public void UpdateCharity(ICharity charity)
 {
     _charityList[charity.Id] = charity;
 }
 public int CreateCharity(ICharity charity)
 {
     _charityList.Add(charity.Id, charity);
     return charity.Id;
 }
        public override void UpdateCharity(ICharity charityDTO)
        {
            Charity oldC = _store.Charities
                .Include(x => x.CreatedBy)
                .Include(x => x.UpdatedBy)
                .Include(x => x.Locations)
                .Single(x => x.Id == charityDTO.Id);

            _store.Entry(oldC).CurrentValues.SetValues(charityDTO);

            if (charityDTO.Category != null)
            {
                oldC.CategoryId = charityDTO.Category.Id;
            }

            if (charityDTO.CreatedBy != null)
            {
                oldC.CreatedById = charityDTO.CreatedBy.Id;
            }

            if (charityDTO.UpdatedBy != null)
            {
                oldC.UpdatedById = charityDTO.UpdatedBy.Id;
            }

            _store.SaveChanges();
        }
 public void UpdateCharity(ICharity charity)
 {
     _charityList[charity.Id] = charity;
 }
 public int CreateCharity(ICharity charity)
 {
     _charityList.Add(charity.Id, charity);
     return(charity.Id);
 }