Exemple #1
0
        public async Task <IActionResult> Edit(int id, Subcontractor subcontractor)
        {
            if (id != subcontractor.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(subcontractor);
                    await _context.SaveChangesAsync();

                    TempData["Toast"] = Toasts.Saved;
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!SubcontractorExists(subcontractor.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(subcontractor));
        }
 public string Post([FromBody] Subcontractor subcontractor)
 {
     //Create
     db.Subcontractor.Add(subcontractor);
     db.SaveChanges();
     return(JsonConvert.SerializeObject(subcontractor));
 }
        public ActionResult DeleteConfirmed(int id)
        {
            Subcontractor subcontractor = db.Subcontractors.Find(id);

            db.Subcontractors.Remove(subcontractor);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
 public ActionResult Edit([Bind(Include = "SubcontractorID,CompanyName,subcontractorPhone,subcontractor_TypeID")] Subcontractor subcontractor)
 {
     if (ModelState.IsValid)
     {
         db.Entry(subcontractor).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(subcontractor));
 }
 public List<string> GetSubcontractorActivities(string id) {
     List<string> retActivities = new List<string>();
     Subcontractor mySub = projectSubs.Find(sub => sub.id == id);
     if (mySub != null) {
         foreach(string tc in mySub.activities) {
             retActivities.Add(tc);
         }
     }
     return retActivities;
 }
        public ActionResult Create([Bind(Include = "SubcontractorID,CompanyName,subcontractorPhone,subcontractor_TypeID")] Subcontractor subcontractor)
        {
            if (ModelState.IsValid)
            {
                db.Subcontractors.Add(subcontractor);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(subcontractor));
        }
        // GET: Subcontractors/Delete/5
        public ActionResult Delete(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            Subcontractor subcontractor = db.Subcontractors.Find(id);

            if (subcontractor == null)
            {
                return(HttpNotFound());
            }
            return(View(subcontractor));
        }
Exemple #8
0
        public async Task <IActionResult> Create(Subcontractor subcontractor)
        {
            if (ModelState.IsValid)
            {
                subcontractor.CreatedDate  = DateTime.Now;
                subcontractor.ModifiedDate = DateTime.Now;
                subcontractor.Id           = _context.Subcontractors.Max(c => c.Id) + 1;

                _context.Add(subcontractor);
                await _context.SaveChangesAsync();

                TempData["Toast"] = Toasts.Created;
                return(RedirectToAction(nameof(Index)));
            }
            return(View(subcontractor));
        }
        public void syncContract(Staff staff)
        {
            try
            {
                var doc = database.GetDocument(staff.Id + "");

                staff.FirstName = doc.GetProperty("firstName").ToString();
                staff.LastName  = doc.GetProperty("lastName").ToString();
                staff.Id        = Int32.Parse(doc.GetProperty("userid").ToString());

                foreach (JObject contractDoc in (JArray)doc.GetProperty("contracts"))
                {
                    //look for any contract with the same contract id then update or add if necessary
                    Subcontractor contract = null;
                    bool          foundSubcontractorDetail = false;
                    foreach (Subcontractor lookupSubcon in staff.Contracts)
                    {
                        if (lookupSubcon.Id == (int)contractDoc.GetValue("subcontractors_id"))
                        {
                            foundSubcontractorDetail = true;
                            contract = lookupSubcon;
                            break;
                        }
                    }
                    if (!foundSubcontractorDetail)
                    {
                        contract = new Subcontractor();
                    }

                    JObject contractSubcontractorDetail = (JObject)contractDoc.GetValue("subcontractors_detail");
                    contract.StaffRate      = (float)contractSubcontractorDetail.GetValue("php_monthly");
                    contract.ClientPrice    = (float)contractSubcontractorDetail.GetValue("client_price");
                    contract.StaffEmail     = (string)contractSubcontractorDetail.GetValue("staff_email");
                    contract.Id             = (int)contractDoc.GetValue("subcontractors_id");
                    contract.JobDesignation = (string)contractSubcontractorDetail.GetValue("job_designation");
                    JObject leadsDetail = (JObject)contractDoc.GetValue("leads_detail");
                    Client  client      = new Client();
                    client.Id        = (int)leadsDetail.GetValue("id");
                    client.FirstName = (string)leadsDetail.GetValue("fname");
                    client.LastName  = (string)leadsDetail.GetValue("lname");
                    contract.Client  = client;
                    if (!foundSubcontractorDetail)
                    {
                        staff.Contracts.Add(contract);
                    }
                }

                /*
                 * //var doc = database.GetDocument(staff.Id + "");
                 * doc.Update((UnsavedRevision newRevision) =>
                 * {
                 *  var properties = newRevision.Properties;
                 *  properties["firstName"] = "Norman";
                 *  properties["lastName"] = "Pogi";
                 *  return true;
                 * });
                 */
            }
            catch (Exception e)
            {
                Console.WriteLine("ERROR : " + e);
            }
        }
 public string Delete([FromBody] Subcontractor subcontractor)
 {
     db.Subcontractor.Remove(subcontractor);
     db.SaveChanges();
     return(JsonConvert.SerializeObject("Ok"));
 }
 public void Put(int id, [FromBody] Subcontractor subcontractor)
 {
     //Update
     db.Subcontractor.Update(subcontractor);
     db.SaveChanges();
 }
Exemple #12
0
        public async Task <IActionResult> OnPostAsync(string returnUrl = null)
        {
            returnUrl ??= Url.Content("~/");

            ExternalLogins = (await _signInManager.GetExternalAuthenticationSchemesAsync()).ToList();

            if (ModelState.IsValid)
            {
                // This doesn't count login failures towards account lockout
                // To enable password failures to trigger account lockout, set lockoutOnFailure: true
                var appUser = await _signInManager.PasswordSignInAsync(Input.Email, Input.Password, Input.RememberMe, lockoutOnFailure : false);

                //Check if user is a subcontractor
                Subcontractor = (await _context.Subcontractor
                                 .FromSqlInterpolated($"EXEC SPR_GPR_Subcontractor @SubcontractorID={Input.Email}, @Password={null}")
                                 .ToListAsync())
                                .FirstOrDefault();

                if (Subcontractor == null)
                {
                    //return NotFound();
                }

                ContextType contextType = ContextType.Domain;
                //Using a different context to query AD from the app
                PrincipalContext appADContext = new(contextType, "BMIS", "Users", "centimesupport", "pr0supp0rt");
                PrincipalContext userContext  = new(contextType, "BMIS", "Users", Input.Email, Input.Password);
                var domainContext             = new PrincipalContext(ContextType.Domain);
                var windowsUser = UserPrincipal.FindByIdentity(domainContext, Input.Email);

                string windowsUsername = Input.Email;
                string windowsEmail    = null;

                //Remove domain part from username if entered at start - e.g. BMIS\r.wilson
                if (windowsUsername.IndexOf("\\") > 0)
                {
                    windowsUsername = windowsUsername.Split("\\").Last();
                }

                //Remove domain part in entered in email address format - e.g. [email protected]
                if (windowsUsername.IndexOf("@") > 0)
                {
                    windowsUsername = windowsUsername.Split("@").First();
                    windowsEmail    = windowsUsername;
                }

                if (windowsUser != null)
                {
                    //If matching Windows user found
                    if (appADContext.ValidateCredentials(Input.Email, Input.Password) == true)
                    {
                        string email              = windowsEmail;
                        string normalizedEmail    = null;
                        string userName           = windowsUsername;
                        string normalizedUserName = windowsUsername.ToUpper();
                        string forename           = null;
                        string surname            = null;

                        if (windowsEmail != null)
                        {
                            normalizedEmail = windowsEmail.ToUpper();
                        }

                        using (var context = new PrincipalContext(ContextType.Domain))
                        {
                            var principal = UserPrincipal.FindByIdentity(context, windowsUsername);
                            forename = principal.GivenName;
                            surname  = principal.Surname;
                        }

                        ApplicationUser applicationUser = new ApplicationUser
                        {
                            UserName           = userName,
                            NormalizedUserName = normalizedUserName,
                            Email           = email,
                            NormalizedEmail = normalizedEmail,
                            Forename        = forename,
                            Surname         = surname
                        };

                        var claims = new List <Claim>
                        {
                            new Claim(ClaimTypes.Name, windowsUsername, Input.Password),
                            new Claim(ClaimTypes.Role, "BMIS"),
                        };

                        if (applicationUser.Forename != null)
                        {
                            claims.Add(new Claim("Forename", applicationUser.Forename));
                        }
                        if (applicationUser.Surname != null)
                        {
                            claims.Add(new Claim("Surname", applicationUser.Surname));
                        }

                        var claimsIdentity = new ClaimsIdentity(
                            claims, CookieAuthenticationDefaults.AuthenticationScheme);

                        var authProperties = new AuthenticationProperties
                        {
                            //AllowRefresh = <bool>,
                            // Refreshing the authentication session should be allowed.

                            //ExpiresUtc = DateTimeOffset.UtcNow.AddMinutes(10),
                            // The time at which the authentication ticket expires. A
                            // value set here overrides the ExpireTimeSpan option of
                            // CookieAuthenticationOptions set with AddCookie.

                            IsPersistent = Input.RememberMe
                                           // Whether the authentication session is persisted across
                                           // multiple requests. When used with cookies, controls
                                           // whether the cookie's lifetime is absolute (matching the
                                           // lifetime of the authentication ticket) or session-based.

                                           //IssuedUtc = <DateTimeOffset>,
                                           // The time at which the authentication ticket was issued.

                                           //RedirectUri = <string>
                                           // The full path or absolute URI to be used as an http
                                           // redirect response value.
                        };

                        await _signInManager.SignInWithClaimsAsync(applicationUser, authProperties, claims);

                        //await HttpContext.SignInAsync(
                        //CookieAuthenticationDefaults.AuthenticationScheme,
                        //new ClaimsPrincipal(claimsIdentity),
                        //authProperties);

                        _logger.LogInformation("User logged in.");
                        return(LocalRedirect(returnUrl));
                    }
                    else
                    {
                        ModelState.AddModelError(string.Empty, "Invalid Windows User login attempt.");
                        return(Page());
                    }
                }
                else if (Subcontractor != null)
                {
                    //If matching subcontractor found
                    Subcontractor = (await _context.Subcontractor
                                     .FromSqlInterpolated($"EXEC SPR_GPR_Subcontractor @SubcontractorID={Input.Email}, @Password={Input.Password}")
                                     .ToListAsync())
                                    .FirstOrDefault();

                    if (Subcontractor != null)
                    {
                        string normalizedEmail = null;
                        if (Subcontractor.Email != null)
                        {
                            normalizedEmail = Subcontractor.Email.ToUpper();
                        }

                        ApplicationUser applicationUser = new ApplicationUser
                        {
                            UserName           = Subcontractor.SubcontractorID,
                            NormalizedUserName = Subcontractor.SubcontractorID.ToUpper(),
                            Email           = Subcontractor.Email,
                            NormalizedEmail = normalizedEmail,
                            Forename        = Subcontractor.Name,
                            Surname         = null
                        };

                        var claims = new List <Claim>
                        {
                            new Claim(ClaimTypes.Name, Input.Email, Input.Password),
                            new Claim("Forename", applicationUser.Forename),
                            //new Claim("Surname", applicationUser.Surname),
                            new Claim(ClaimTypes.Role, "Subcontractor"),
                        };

                        var claimsIdentity = new ClaimsIdentity(
                            claims, CookieAuthenticationDefaults.AuthenticationScheme);

                        var authProperties = new AuthenticationProperties
                        {
                            IsPersistent = Input.RememberMe
                        };

                        await _signInManager.SignInWithClaimsAsync(applicationUser, authProperties, claims);

                        //await HttpContext.SignInAsync(
                        //CookieAuthenticationDefaults.AuthenticationScheme,
                        //new ClaimsPrincipal(claimsIdentity),
                        //authProperties);

                        _logger.LogInformation("User logged in.");
                        return(LocalRedirect(returnUrl));
                    }
                    else
                    {
                        ModelState.AddModelError(string.Empty, "Invalid Subcontractor User login attempt.");
                        return(Page());
                    }
                }
                else if (appUser != null)
                {
                    //If matching app user found
                    if (appUser.Succeeded)
                    {
                        _logger.LogInformation("User logged in.");
                        return(LocalRedirect(returnUrl));
                    }
                    if (appUser.RequiresTwoFactor)
                    {
                        return(RedirectToPage("./LoginWith2fa", new { ReturnUrl = returnUrl, RememberMe = Input.RememberMe }));
                    }
                    if (appUser.IsLockedOut)
                    {
                        _logger.LogWarning("User account locked out.");
                        return(RedirectToPage("./Lockout"));
                    }
                    else
                    {
                        ModelState.AddModelError(string.Empty, "Invalid Application User login attempt.");
                        return(Page());
                    }
                }
            }

            // If we got this far, something failed, redisplay form
            return(Page());
        }
Exemple #13
0
        public IActionResult Create()
        {
            Subcontractor sub = new Subcontractor();

            return(View(sub));
        }
 public void AddProjectSub(JSONNode sub) {
     Subcontractor subToAdd = new Subcontractor(sub);
     projectSubs.Add(subToAdd);
 }