Exemplo n.º 1
0
        public async Task <IActionResult> OnGetAsync(int?LinkID)
        {
            SalesRepEmployLink = new SalesRepCodeEmployeeNoLink {
            };


            if (LinkID != null)
            {
                SalesRepEmployLink = await _context.SalesRepCodeEmployeeNoLink.Include(e => e.Employee).Include(s => s.SalesRep)
                                     .SingleOrDefaultAsync(m => m.SalesRepCodeEmployeeNoLinkID == LinkID);
            }
            return(Page());
        }
Exemplo n.º 2
0
        //Updates the existing SalesLink Details
        public async Task <IActionResult> OnPutUpdateRepEmployeeLink([FromBody] SalesRepCodeEmployeeNoLink obj)
        {
            if (obj != null && (HttpContext.User.IsInRole("Admin") || HttpContext.User.IsInRole("HR")))
            {
                try
                {
                    _context.Attach(obj).State = EntityState.Modified;
                    await _context.SaveChangesAsync();

                    return(new JsonResult(obj));
                }
                catch (DbUpdateException d)
                {
                    return(new JsonResult("Rep Employee Changes not saved." + d.InnerException.Message));
                }
            }
            return(new JsonResult("Rep Employee not saved. You do not have access rights to save these changes"));
        }
Exemplo n.º 3
0
        public async Task <IActionResult> OnDeleteDelete([FromBody] SalesRepCodeEmployeeNoLink obj)
        {
            if (obj != null && HttpContext.User.IsInRole("Admin"))
            {
                try
                {
                    _context.SalesRepCodeEmployeeNoLink.Remove(obj);
                    await _context.SaveChangesAsync();

                    return(new JsonResult("SalesRepEmployeeLink removed successfully"));
                }
                catch (DbUpdateException d)
                {
                    return(new JsonResult("SalesRepEmployeeLink not removed." + d.InnerException.Message));
                }
            }
            else
            {
                return(new JsonResult("SalesRepEmployeeLink not removed."));
            }
        }
Exemplo n.º 4
0
        //Inserts a new Employee with details
        public async Task <IActionResult> OnPostInsertRepEmployeeLink([FromBody] SalesRepCodeEmployeeNoLink obj)
        {
            if (obj != null && (HttpContext.User.IsInRole("Admin") || HttpContext.User.IsInRole("HR")))
            {
                try
                {
                    _context.Add(obj);
                    await _context.SaveChangesAsync();

                    int id = obj.SalesRepCodeEmployeeNoLinkID; // Yes it's here
                    return(new JsonResult(obj));
                }
                catch (DbUpdateException d)
                {
                    return(new JsonResult("Sales Rep Employee Not Added." + d.InnerException.Message));
                }
            }

            else
            {
                return(new JsonResult("Sales Rep Not Inserted"));
            }
        }