Exemplo n.º 1
0
        public IActionResult SaveBiographicResponse([FromBody] BiographicResponse biographicResponse)
        {
            if (biographicResponse == null)
            {
                return(BadRequest("Error, Make sure your selection is valid"));
            }

            try
            {
                Project  project  = _context.Projects.FirstOrDefault(id => id.ProjectIdentifier.ToString() == biographicResponse.ProjectIdentifier);
                Employee employee = _context.Employees.FirstOrDefault(id => (id.Identifier.ToString() == biographicResponse.EmployeeIdentifier));

                EmployeeBiographic response = _context.EmployeeBiographics.FirstOrDefault(id => (id.EmployeeId == employee.EmployeeId) && (id.BiographicId == biographicResponse.BiographicId));

                response.IsBiographicDetail = true;
                response.BiographicDetailId = biographicResponse.BiographicDetailId;

                _context.EmployeeBiographics.Update(response);
                _context.SaveChanges();

                return(Ok(response));
            }
            catch (Exception Ex)
            {
                return(BadRequest("Something bad happened! " + Ex.Message));
            }
        }
Exemplo n.º 2
0
        public IActionResult SaveBiographicType([FromBody] BiographicDetailModel model)
        {
            if (model == null)
            {
                return(BadRequest("Error, Make sure form is complete!"));
            }

            try
            {
                BiographicDetail biographicChecker = _context.BiographicDetails.FirstOrDefault(id => (id.Name.ToUpper() == model.Name.ToUpper()) && (id.BiographicId == model.BiographicId));

                if (biographicChecker != null)
                {
                    return(BadRequest("Biographic detail with this name for this biographic type already exists."));
                }

                BiographicDetail biographicDetail = new BiographicDetail();
                biographicDetail.BiographicId = model.BiographicId;
                biographicDetail.Name         = model.Name;
                biographicDetail.ClientId     = model.ClientId;
                biographicDetail.TenantId     = model.TenantId;
                biographicDetail.Reference    = model.Reference;
                biographicDetail.DateStamp    = DateTime.Now;

                _context.BiographicDetails.Add(biographicDetail);
                _context.SaveChanges();

                return(Ok());
            }
            catch (Exception Ex)
            {
                return(BadRequest("Something bad happened! " + Ex.Message));
            }
        }
Exemplo n.º 3
0
        public IActionResult SaveEmployee([FromBody] Employee model)
        {
            if (model == null)
            {
                return(BadRequest("Error, Make sure form is complete!"));
            }

            try
            {
                Employee employee   = new Employee();
                Employee isEmployee = _context.Employees.FirstOrDefault(id => (id.Email == model.Email) && (id.TenantId == model.TenantId) && (id.ClientId == model.ClientId));
                if (isEmployee == null)
                {
                    employee.DateStamp   = DateTime.Now;
                    employee.Email       = model.Email;
                    employee.Name        = model.Name;
                    employee.Surname     = model.Surname;
                    employee.Reference   = model.Reference;
                    employee.Title       = model.Title;
                    employee.IsSendEmail = model.IsSendEmail;
                    employee.ClientId    = model.ClientId;
                    employee.TenantId    = model.TenantId;
                    employee.AssetNodeId = model.AssetNodeId;
                    employee.Identifier  = Guid.NewGuid();

                    _context.Employees.Add(employee);
                    _context.SaveChanges();
                }


                ClientEmployee isClientEmployee = _context.ClientEmployees.FirstOrDefault(id => (id.TenantId == model.TenantId) && (id.ClientId == model.ClientId) && (id.EmployeeId == model.EmployeeId));

                if (isClientEmployee == null)
                {
                    ClientEmployee clientEmployee = new ClientEmployee();
                    clientEmployee.DateStamp  = DateTime.Now;
                    clientEmployee.ClientId   = model.ClientId;
                    clientEmployee.TenantId   = model.TenantId;
                    clientEmployee.EmployeeId = employee.EmployeeId;
                    clientEmployee.Reference  = model.Reference;

                    _context.ClientEmployees.Add(clientEmployee);
                    _context.SaveChanges();
                }


                return(Ok());
            }
            catch (Exception Ex)
            {
                return(BadRequest("Something bad happened! " + Ex.Message));
            }
        }
        public IActionResult AddProjParticipant([FromBody] RemoveProjectParticipant model)
        {
            if (model == null)
            {
                return(BadRequest("Error, Make sure form is complete!"));
            }

            try
            {
                RemoveProjectParticipant participantExists = _context.RemoveProjectParticipants.FirstOrDefault(id => (id.ProjectId == model.ProjectId) && (id.EmployeeId == model.EmployeeId));

                _context.RemoveProjectParticipants.Remove(participantExists);
                _context.SaveChanges();

                return(Ok());
            }
            catch (Exception Ex)
            {
                return(BadRequest("Something bad happened. " + Ex.Message));
            }
        }
Exemplo n.º 5
0
        public IActionResult SaveTenantUser([FromBody] TenantUser model)
        {
            string password = CreatePassword(6);
            string url      = $"{_configuration["FrontEndUrl"]}";

            if (model == null)
            {
                return(BadRequest("Error, Make sure tenant form is complete!"));
            }

            ApplicationUser userChecker = _contextUsers.Users.FirstOrDefault(id => id.Email == model.Email);

            if (userChecker != null)
            {
                return(BadRequest("Error, User with this email already exists. Contact administrator."));
            }

            try
            {
                ApplicationUser applicationUser = new ApplicationUser();
                applicationUser.FirstName = model.FirstName;
                applicationUser.LastName  = model.LastName;
                applicationUser.Email     = model.Email;
                applicationUser.UserName  = model.Email;
                applicationUser.Reference = model.Reference;
                applicationUser.DateStamp = DateTime.Now;
                applicationUser.TenantId  = model.TenantId;

                IdentityResult result = _userManager.CreateAsync(applicationUser, password).Result;

                _context.SaveChanges();

                _userManager.AddToRoleAsync(applicationUser, "ADMINISTRATOR");
                _contextUsers.SaveChanges();

                var smtp = new SmtpClient
                {
                    Host           = "smtp.gmail.com",
                    Port           = 587,
                    EnableSsl      = true,
                    DeliveryMethod = SmtpDeliveryMethod.Network,
                    Credentials    = new NetworkCredential("*****@*****.**", "StratisQ@2020"),
                    Timeout        = 20000
                };

                using (var message = new MailMessage("*****@*****.**", model.Email)
                {
                    IsBodyHtml = true,
                    Subject = "StratisQ: " + _contextUsers.Tenants.FirstOrDefault(id => id.TenantId == model.TenantId).TenantKey + " Account",
                    Body = "<html><body>Hi " + applicationUser.FirstName + ", <br/>Your account has created sucessfully: <br/><br/>Link: " + url + "<br/><br/>Username: "******"<br/>Password: "******" <br/><br/><br/><p>StratisQ</p></body></html></body></html>"
                })
                {
                    smtp.Send(message);
                }

                return(Ok());
            }
            catch (Exception Ex)
            {
                return(BadRequest("Something bad happened! " + Ex.Message));
            }
        }
Exemplo n.º 6
0
        public IActionResult PostOrganization([FromBody] AssetNode assetNode)
        {
            if (assetNode == null)
            {
                return(BadRequest("Something bad happened. Object is null"));
            }

            if (assetNode.ParentAssetNodeId != 0)
            {
                AssetNode asset = _context.AssetNodes.FirstOrDefault(id => (id.TenantId == assetNode.TenantId) && (id.ClientId == assetNode.ClientId) && (id.Name == assetNode.Name));

                if (asset != null)
                {
                    return(BadRequest("There is already a node with this name: " + assetNode.Name));
                }
            }

            try
            {
                AssetNode model = new AssetNode();
                model.ParentAssetNodeId = assetNode.ParentAssetNodeId;
                model.Name           = assetNode.Name.ToUpper();
                model.DateStamp      = DateTime.Now;
                model.Reference      = assetNode.Reference;
                model.ClientId       = assetNode.ClientId;
                model.TenantId       = assetNode.TenantId;
                model.Size           = assetNode.Size;
                model.LastEditedDate = DateTime.Now;
                model.LastEditedBy   = assetNode.Reference;

                if (model.ParentAssetNodeId == 0)
                {
                    model.RootAssetNodeId = 0;
                }
                else
                {
                    model.RootAssetNodeId = _context.AssetNodes.FirstOrDefault(id => id.AssetNodeId == model.ParentAssetNodeId).RootAssetNodeId;
                }


                _context.AssetNodes.Add(model);
                _context.SaveChanges();

                if (model.ParentAssetNodeId == 0)
                {
                    model.RootAssetNodeId = model.AssetNodeId;
                    model.Height          = model.Height + 1;
                }
                else
                {
                    //model.RootAssetNodeId = _context.AssetNodes.FirstOrDefault(id => id.ParentAssetNodeId == model.ParentAssetNodeId).RootAssetNodeId;
                    model.Height = _context.AssetNodes.FirstOrDefault(id => id.AssetNodeId == model.ParentAssetNodeId).Height + 1;
                }

                _context.AssetNodes.Update(model);
                _context.SaveChanges();

                return(Ok());
            }
            catch (Exception Ex)
            {
                return(BadRequest("Something bad happened! " + Ex.Message));
            }
        }