Example #1
0
File: Site.cs Project: Crisp771/Chc
        public Site CreateSite(Site site, int userId)
        {
            var newsite = new tblSite()
            {
                ActionDetails  = site.ActionDetails,
                Address        = site.Address,
                ContactDetails = site.ContactDetails,
                SICcode        = site.SICcode,
                SiteID         = site.SiteID,
                SiteName       = site.SiteName,
                Deleted        = site.Deleted
            };

            _context.tblSites.Add(newsite);
            _context.SaveChanges();

            var audit = new SiteAudit()
            {
                Event         = string.Format("Site {1} created with id {0}", newsite.SiteID, newsite.SiteName),
                EventDateTime = DateTime.Now,
                SiteID        = newsite.SiteID,
                UserID        = userId
            };

            audit.Audit();

            return(new Site(newsite));
        }
Example #2
0
        public async Task <ActionResult <tblSite> > PostTblSite(tblSite tblSite)
        {
            _context.tblSite.Add(tblSite);
            await _context.SaveChangesAsync();

            return(CreatedAtAction("GetTblSite", new { id = tblSite.SiteID }, tblSite));
        }
Example #3
0
        //methods
        public void Insert()
        {
            try
            {
                LFGuestSystemEntities oDc = new LFGuestSystemEntities();
                tblSite t_site            = new tblSite();
                t_site.SiteID = 1;
                // automatically calculate the new siteID
                if (oDc.tblSites.Count() > 0)
                {
                    t_site.SiteID = oDc.tblSites.Max(p => p.SiteID) + 1;
                }

                // fill in the data
                this.SiteID     = t_site.SiteID;
                t_site.SiteName = this.SiteName;
                t_site.Street   = this.Street;
                t_site.City     = this.City;
                t_site.State    = this.State;
                t_site.ZipCode  = this.ZipCode;
                oDc.tblSites.Add(t_site);
                oDc.SaveChanges();
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Example #4
0
        public async Task <IActionResult> PutTblSite(int id, tblSite tblSite)
        {
            if (id != tblSite.SiteID)
            {
                return(BadRequest());
            }

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

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

            return(NoContent());
        }