public ActionResult CreateGroupTemplate(Guid id)
        {
            try
            {
                LcpsAdsGroup ou = new LcpsAdsGroup(id);
                GroupTemplate t = new GroupTemplate();
                t.GroupId = id;
                t.TemplateName = ou.Name;

                if (string.IsNullOrEmpty(ou.Description))
                    t.Description = "No aescription available";
                else
                    t.Description = ou.Description;

                DbContext.GroupTemplates.Add(t);
                DbContext.SaveChanges();

                return Content("Success", "text/html");
            }
            catch (Exception ex)
            {
                AnvilExceptionCollector ec = new AnvilExceptionCollector(ex);
                return Content(ec.ToUL(), "text/html");
            }
        }
Пример #2
0
        public ActionResult CreateOuTemplate(Guid id)
        {
            try
            {
                LcpsAdsOu ou = new LcpsAdsOu(id);
                OUTemplate t = new OUTemplate();
                t.OUId = id;
                t.TemplateName = ou.Name;
                t.Description = ou.Description;
                DbContext.OUTemplates.Add(t);
                DbContext.SaveChanges();

                return Content("Success", "text/html");
            }
            catch (Exception ex)
            {
                AnvilExceptionCollector ec = new AnvilExceptionCollector(ex);
                return Content(ec.ToUL(), "text/html");
            }
        }
Пример #3
0
        public ActionResult LookupComputer(string name)
        {
            string result = "Success";

               try
               {
               if (String.IsNullOrEmpty(name))
                   throw new Exception("Please supply a computer name to search for");

               ApplicationBase app = LcpsDbContext.DefaultApp;
               string un = string.Format("{0}\\{1}", app.LDAPDomain, app.LDAPUserName);

               RemoteComputer c = new RemoteComputer(name, un, app.LDAPPassword);

               c.Refresh();
               }
            catch(Exception ex)
               {
               AnvilExceptionCollector ec = new AnvilExceptionCollector(ex);
               result = ec.ToUL();
               }

               return Content(result);
        }
Пример #4
0
        public void Validate(Infrastructure.LcpsDbContext context)
        {
            // ---------- Validate Position Info

            try
            {
                _staffDefinition = new HRStaffPositionDefinition(this.BuildingId, this.EmployeeTypeId, this.JobTitleId, context);
            }
            catch (Exception ex)
            {
                AnvilExceptionCollector ec = new AnvilExceptionCollector(ex);
                ValidationReport = ec.ToLineBreakString();
                ValidationStatus = ImportRecordStatus.danger;
                return;
            }

            // ---------- Valdiate Birthdate
            try
            {
                DateTime d = this.Birthdate;
            }
            catch (Exception ex)
            {
                AnvilExceptionCollector ec = new AnvilExceptionCollector(new Exception("Invalid bithdate", ex));
                ValidationReport = ec.ToLineBreakString();
                ValidationStatus = ImportRecordStatus.danger;
                return;
            }

            // ---------- Valdiate Status Qualifier
            try
            {
                HRStaffPositionQualifier q = this.Status;
            }
            catch (Exception ex)
            {
                AnvilExceptionCollector ec = new AnvilExceptionCollector(new Exception("Invalid status", ex));
                ValidationReport = ec.ToLineBreakString();
                ValidationStatus = ImportRecordStatus.danger;
                return;
            }

            // ---------- Validate gender
            try
            {
                HRGenders g = this.Gender;
            }
            catch (Exception ex)
            {
                AnvilExceptionCollector ec = new AnvilExceptionCollector(new Exception("Invalid gender", ex));
                ValidationReport = ec.ToLineBreakString();
                ValidationStatus = ImportRecordStatus.danger;
                return;
            }

            // --------- Validate Required fields
            try
            {
                AnvilEntity e = new AnvilEntity(this);
                e.RequiredFields.Add("StaffId");
                e.RequiredFields.Add("FirstName");
                e.RequiredFields.Add("LastName");

                e.Validate();
            }
            catch (Exception ex)
            {
                AnvilExceptionCollector ec = new AnvilExceptionCollector(ex);
                ValidationReport = ec.ToLineBreakString();
                ValidationStatus = ImportRecordStatus.danger;
                return;

            }

            ValidationStatus = ImportRecordStatus.success;
            ValidationReport = "Validated";
        }
Пример #5
0
        public void Import(Infrastructure.LcpsDbContext context)
        {
            if (CrudStatus == ImportCrudStatus.None)
                return;

            Guid _staffKey = Guid.Empty;

            HRStaffPosition[] pp = context.StaffPositions.Where(x => x.StaffMemberId.Equals(_staffKey)).ToArray();
            if(pp.Count() > 0)
            {
                context.StaffPositions.RemoveRange(pp);
                context.SaveChanges();
            }

            try
            {

                if (CrudStatus.HasFlag(ImportCrudStatus.InsertMember))
                {
                    HRStaff staff = new HRStaff()
                    {
                        StaffKey = Guid.NewGuid(),
                        StaffId = this.StaffId,
                        Birthdate = this.Birthdate,
                        FirstName = this.FirstName,
                        MiddleInitial = this.MiddleInitial,
                        LastName = this.LastName,
                        Gender = this.Gender
                    };

                    _staffKey = staff.StaffKey;

                    context.StaffMembers.Add(staff);
                }

                if (CrudStatus.HasFlag(ImportCrudStatus.UpdateMember))
                {
                    HRStaff staff = context.StaffMembers.First(x => x.StaffId.ToLower() == this.StaffId.ToLower());
                    staff.Birthdate = this.Birthdate;
                    staff.FirstName = this.FirstName;
                    staff.MiddleInitial = this.MiddleInitial;
                    staff.LastName = this.LastName;
                    staff.Gender = this.Gender;

                    _staffKey = staff.StaffKey;

                    context.Entry(staff).State = System.Data.Entity.EntityState.Modified;
                }

                if (CrudStatus.HasFlag(ImportCrudStatus.CreateMembership))
                {
                    if (_staffKey.Equals(Guid.Empty))
                        _staffKey = context.StaffMembers.First(x => x.StaffId.ToLower() == this.StaffId.ToLower()).StaffKey;

                    HRStaffPosition p = new HRStaffPosition()
                    {
                        StaffMemberId = _staffKey,
                        PositionKey = Guid.NewGuid(),
                        BuildingKey = _staffDefinition.Building.BuildingKey,
                        EmployeeTypeKey = _staffDefinition.EmployeeType.EmployeeTypeLinkId,
                        JobTitleKey = _staffDefinition.JobTitle.JobTitleKey,
                        Status = this.Status,
                        FiscalYear = this.FiscalYear
                    };

                    context.StaffPositions.Add(p);
                }

                if (CrudStatus.HasFlag(ImportCrudStatus.UpdateMembership))
                {
                    if (_staffKey.Equals(Guid.Empty))
                        _staffKey = context.StaffMembers.First(x => x.StaffId.ToLower() == this.StaffId.ToLower()).StaffKey;

                    HRStaffPosition p = context.StaffPositions
                        .First(x => x.StaffMemberId.Equals(_staffKey)
                        & x.BuildingKey.Equals(_staffDefinition.Building.BuildingKey)
                        & x.EmployeeTypeKey.Equals(_staffDefinition.EmployeeType.EmployeeTypeLinkId)
                        & x.JobTitleKey.Equals(_staffDefinition.JobTitle.JobTitleKey));

                    p.Status = this.Status;
                    p.FiscalYear = this.FiscalYear;

                    context.Entry(p).State = System.Data.Entity.EntityState.Modified;
                }

                context.SaveChanges();

                ImportStatus = ImportRecordStatus.success;
            }
            catch (Exception ex)
            {
                AnvilExceptionCollector ec = new AnvilExceptionCollector(ex);
                ImportStatus = ImportRecordStatus.danger;
                ImportReport = ec.ToLineBreakString();
            }
        }
Пример #6
0
        public ActionResult AddStaffClause(StaffFilterClauseModel m)
        {
            if (!m.BuildingInclude & !m.EmployeeTypeInclude & !m.JobTitleInclude & !m.StatusInclude & !m.StaffIdInclude & !m.LastNameInclude)
                ModelState.AddModelError("", "Please include at least one field in the filter");

            MemberFilter f = null;

            try
            {
                f = DbContext.MemberFilters.First(x => x.FilterId.Equals(m.FilterId));
            }
            catch
            {
                ModelState.AddModelError("", "Invalid filter id");
            }

            int count = DbContext.StaffFilterClauses.Where(x => x.FilterId.Equals(m.FilterId)).Count();

            bool hasErrors = ViewData.ModelState.Values.Any(x => x.Errors.Count > 1);
            List<ModelState> errors = ViewData.ModelState.Values.Where(x => x.Errors.Count() > 0).ToList();

            if (ModelState.IsValid)
            {
                try
                {
                    StaffFilterClause c = new StaffFilterClause();

                    AnvilEntity e = new AnvilEntity(m);
                    e.CopyTo(c);
                    c.StaffFilterClauseId = Guid.NewGuid();
                    c.SortIndex = count;
                    DbContext.StaffFilterClauses.Add(c);
                    DbContext.SaveChanges();
                }
                catch (Exception ex)
                {
                    return View("~/Views/Shared/Error.cshtml", new AnvilExceptionModel(ex, "Create Staff Clause", "My", "Contacts", "EditStaffFilter"));
                }
            }
            else
            {
                AnvilExceptionCollector ec = new AnvilExceptionCollector("The staff filter clause could not be validated");
                foreach (ModelState ms in errors)
                {
                    foreach (var x in ms.Errors)
                    {
                        ec.Add(x.ErrorMessage);
                    }
                }

                AnvilExceptionModel em = new AnvilExceptionModel(ec.ToException(), "Create Staff Filter Clause", null, null, null);

                MemberFilterModel fm = new MemberFilterModel(f);

                fm.Exception = em;

                return View("EditFilter", fm);
            }

            return RedirectToAction("EditFilter", new { id = m.FilterId });
        }
Пример #7
0
        public void Validate(Infrastructure.LcpsDbContext context)
        {
            // ---------- Vadliate User key
            HRStaff staff = context.StaffMembers.FirstOrDefault(x => x.StaffId.ToLower() == this.EntityId.ToLower());
            if (staff == null)
            {
                Student stu = context.Students.FirstOrDefault(x => x.StudentId.ToLower() == this.EntityId.ToLower());
                if (stu == null)
                {
                    ValidationReport = string.Format("{0} is not a valida student or staff id", this.EntityId);
                    ValidationStatus = ImportRecordStatus.danger;
                    return;
                }
                else
                    _userKey = stu.StudentKey;

            }
            else _userKey = staff.StaffKey;

            // ---------- Validate Fields
            try
            {
                AnvilEntity e = new AnvilEntity(this);
                e.RequiredFields.Add("StaffId");
                e.RequiredFields.Add("UserName");
                e.RequiredFields.Add("Password");
                e.Validate();
            }
            catch (Exception ex)
            {
                AnvilExceptionCollector ec = new AnvilExceptionCollector(ex);
                ValidationReport = ec.ToLineBreakString();
                ValidationStatus = ImportRecordStatus.danger;
                return;
            }

            // ---------- Validate Password
            if(this.Password.Length < 6)
            {
                ValidationReport = "The password must contain at least 6 characters";
                ValidationStatus = ImportRecordStatus.danger;
                return;
            }

            ValidationReport = "Validated";
            ValidationStatus = ImportRecordStatus.success;
        }
Пример #8
0
        public void Import(Infrastructure.LcpsDbContext context)
        {
            try
            {
                if (this.CrudStatus == ImportCrudStatus.InsertMember)
                {
                    LdapAccount ac = new LdapAccount()
                    {
                        AccountId = Guid.NewGuid(),
                        UserKey = _userKey,
                        UserName = this.UserName,
                        InitialPassword = this.Password,
                        Active = this.Active
                    };

                    context.LdapAccounts.Add(ac);
                }
                else
                {
                    LdapAccount ac = context.LdapAccounts
                    .FirstOrDefault(
                        x => x.UserKey.Equals(_userKey)
                        & x.UserName.ToLower() == this.UserName.ToLower()
                    );
                    ac.UserName = this.UserName;
                    ac.Active = this.Active;
                    context.Entry(ac).State = System.Data.Entity.EntityState.Modified;
                }

                context.SaveChanges();

                ImportReport = "Success";
                ImportStatus = ImportRecordStatus.success;

            }
            catch(Exception ex)
            {
                AnvilExceptionCollector ec = new AnvilExceptionCollector(ex);
                ImportReport = ec.ToLineBreakString();
                ImportStatus = ImportRecordStatus.danger;
            }
        }
Пример #9
0
        public void Import()
        {
            List<ImportItem> cc = db.ImportItems.Where(x => x.SessionId.Equals(this.SessionId) & (x.EntityStatus == ImportEntityStatus.Create | x.EntityStatus == ImportEntityStatus.Update)).ToList();

            System.Type t = System.Type.GetType(FullAssemblyTypeName);

            foreach (ImportItem item in cc)
            {

                object i = DeserializeItem(t, item.SerializedData);

                IImportEntity entity = i as IImportEntity;

                switch (item.EntityStatus)
                {
                    case ImportEntityStatus.Create:
                        try
                        {
                            entity.Create();
                            item.Comment = "Added successfuly";
                            item.ImportStatus = ImportResultStatus.success;
                        }
                        catch (Exception ex)
                        {
                            AnvilExceptionCollector ec = new AnvilExceptionCollector(new Exception("Could not create entity", ex));
                            item.Comment = string.Join("\n", ec.ToArray());
                            item.ImportStatus = ImportResultStatus.danger;
                        }
                        break;
                    case ImportEntityStatus.Update:
                        try
                        {
                            entity.Update();
                            item.Comment = "Synced successfuly";
                            item.ImportStatus = ImportResultStatus.success;
                        }
                        catch (Exception ex)
                        {
                            AnvilExceptionCollector ec = new AnvilExceptionCollector(new Exception("Could not modify entity", ex));
                            item.Comment = string.Join("\n", ec.ToArray());
                            item.ImportStatus = ImportResultStatus.danger;
                        }
                        break;
                }

                db.Entry(item).State = System.Data.Entity.EntityState.Modified;
                db.SaveChanges();
            }
        }
Пример #10
0
        public List<StudentRecord> Execute()
        {
            DynamicQueryStatement dqs = ToDynamicQueryStatement();

            try
            {
                StudentsContext context = new StudentsContext();

                List<StudentRecord> students = context.StudentRecords.Where(dqs.Query, dqs.Parms)
                    .OrderBy(x => x.LastName + x.FirstName + x.MiddleInitial)
                    .ToList();

                return students;
            }
            catch (Exception ex)
            {
                AnvilExceptionCollector ec = new AnvilExceptionCollector("Could not get students from database");
                ec.Add(ex);
                ec.Add(dqs.Query);
                throw ec.ToException();

            }
        }
Пример #11
0
        public ActionResult DeleteStaffFilterClause(Guid id)
        {
            string result = "Success";
            try
            {
                StaffFilterClause c = db.StaffFilterClauses.Find(id);
                db.StaffFilterClauses.Remove(c);
                db.SaveChanges();
            }
            catch (Exception ex)
            {
                AnvilExceptionCollector ec = new AnvilExceptionCollector(ex);
                result = ec.ToUL();
            }

            return Content(result, "text/html");
        }
Пример #12
0
        public List<HRStaffRecord> Execute()
        {
            DynamicQueryStatement dqs = ToDynamicQueryStatement();

            try
            {
                HRStaffContext context = new HRStaffContext();
                if (Parms.Count() == 0)
                    return new List<HRStaffRecord>();
                else
                    return context.HRStaffRecords
                        .Where(dqs.Query, dqs.Parms)
                        .OrderBy(x => x.LastName + x.FirstName + x.MiddleInitial)
                        .ToList();

            }
            catch (Exception ex)
            {
                AnvilExceptionCollector ec = new AnvilExceptionCollector("Could not get staff records from the database");
                ec.Add(ex);
                ec.Add(dqs.Query);
                throw ec.ToException();
            }
        }
Пример #13
0
        private void CreateUl(AnvilTreeNode n, ref string output)
        {
            if (n.ItemError == null)
            {
                bool IsParent = (n.Children.Count() > 0);

                if (IsParent)
                {
                    output += "<li><span style='margin-right: 8px;' selectedGlyph='" + n.SelectedItemGlyphCss + "' normalGlyph='" + n.ItemGlyphCss + "'><i class='" + n.InitGlyph + "'></i></span><a value='" + n.Value + "' class='" + n.LinkClass + "'>" + n.Text + "</a>\n";
                    output += "<ul>\n";
                    foreach (AnvilTreeNode child in n.Children)
                    {
                        CreateUl(child, ref output);
                    }
                    output += "</ul></li>\n";
                }
                else
                {
                    output += "<li><span style='margin-right: 8px;' selectedGlyph='" + n.SelectedItemGlyphCss + "' normalGlyph='" + n.ItemGlyphCss + "'><i class='" + n.InitGlyph + "'></i></span><a value='" + n.Value + "' class='" + n.LinkClass + "'>" + n.Text + "</a></li>\n";
                }

            }
            else
            {
                AnvilExceptionCollector ec = new AnvilExceptionCollector(ItemError);
                string result = "<li class='text-danger'>";
                result += ec.ToUL() + "</li>\n";
                output += result;
            }
        }
Пример #14
0
        public void ParseItems(StreamReader reader)
        {
            this.Record();

            int index = 0;

            ItemType = System.Type.GetType(FullAssemblyTypeName);

            while (!reader.EndOfStream)
            {
                string l = reader.ReadLine();
                if (l == null)
                    break;

                if (index == 0)
                {
                    try
                    {
                        FieldNames = l.Split(Delimiter.ToCharArray()[0]);
                        index++;
                    }
                    catch (Exception ex)
                    {
                        AnvilExceptionCollector ec = new AnvilExceptionCollector(ex);
                        ec.Insert(0, "Could not parse the columns from the first line");
                        throw ec.ToException();
                    }
                }
                else
                {
                    if (l.Contains("CONSULT"))
                    {
                        int x = 0;
                        x++;
                    }

                    object sourceItem = null;

                    try
                    {
                        sourceItem = ParseLine(l);
                    }
                    catch (Exception ex)
                    {
                        ImportItem i = new ImportItem()
                        {
                            ImportItemId = Guid.NewGuid(),
                            SessionId = SessionId,
                            Description = l,
                            EntityStatus = ImportEntityStatus.Error,
                            EntryDate = DateTime.Now,
                            LineIndex = index - 1,
                            Comment = string.Join("\n", (new Anvil.v2015.v001.Domain.Exceptions.AnvilExceptionCollector(ex)).ToArray())
                        };

                        try
                        {
                            db.ImportItems.Add(i);
                            db.SaveChanges();
                        }
                        catch (Exception ex2)
                        {
                            AnvilExceptionCollector iEx = new AnvilExceptionCollector(ex2);
                            throw iEx.ToException();
                        }
                    }

                    index++;

                    if (sourceItem != null)
                    {
                        IImportStatus iis = sourceItem as IImportStatus;
                        if (iis == null)
                            throw new Exception("Parse import file failed. The items must implement IImportStatus");

                        IImportEntity iie = sourceItem as IImportEntity;

                        if (iie == null)
                            throw new Exception("Parse import file failed. The items must implement IImportEntity");

                        try
                        {
                            iis.LineIndex = index - 1;
                            iis.ImportItemId = Guid.NewGuid();
                            iis.SessionId = this.SessionId;
                            iis.EntryDate = DateTime.Now;
                            Byte[] _bytes = SerializeItem(sourceItem);
                            iis.SerializedData = _bytes;
                            iis.SourceItem = sourceItem;
                        }
                        catch (Exception ex)
                        {
                            AnvilExceptionCollector ec = new AnvilExceptionCollector(ex);
                            ec.Insert(0, string.Format("Could not serialize item at index {0}", index.ToString()));
                            ec.Insert(0, l);
                            throw ec.ToException();
                        }

                        try
                        {
                            try
                            {
                                iis.Validate();
                            }
                            catch (Exception ex)
                            {
                                AnvilExceptionCollector ec = new AnvilExceptionCollector(ex);
                                iis.Comment = string.Join("\n", ec.ToArray());
                                iis.EntityStatus = ImportEntityStatus.Error;
                            }

                            if (iis.EntityStatus == ImportEntityStatus.Error)
                                goto completesync;

                            if (iie.TargetExists())
                            {
                                if (UpdateIfExists)
                                {
                                    if (iie.IsSyncJustified())
                                        iis.EntityStatus = ImportEntityStatus.Update;
                                    else
                                        iis.EntityStatus = ImportEntityStatus.None;
                                }
                                else
                                    iis.EntityStatus = ImportEntityStatus.Ignore;
                            }
                            else
                            {
                                if (AddIfNotExist)
                                    iis.EntityStatus = ImportEntityStatus.Create;
                                else
                                    iis.EntityStatus = ImportEntityStatus.Ignore;
                            }
                        }

                        catch (Exception ex)
                        {
                            throw new Exception("Could not get sync status of this item", ex);
                        }

                    completesync:
                        iis.SerializedData = SerializeItem(iis);
                        iis.Record();

                    }
                }
            }
        }
Пример #15
0
        public ActionResult RelocateComputer(string b, string r, string u, string n)
        {
            string result = "Success";

            try
            {
                if (String.IsNullOrEmpty(b))
                    throw new Exception("Building ID is required");

                if (String.IsNullOrEmpty(r))
                    throw new Exception("Room ID is required");

                if (String.IsNullOrEmpty(u))
                    throw new Exception("Unit Number is required");

                if (String.IsNullOrEmpty(n))
                    throw new Exception("Computer Name is required");

                ApplicationBase app = LcpsDbContext.DefaultApp;
                string un = string.Format("{0}\\{1}", app.LDAPDomain, app.LDAPUserName);

                RemoteComputer c = new RemoteComputer(n, un, app.LDAPPassword);

                c.Refresh();

                ComputerInfo info = c.ToComputerInfo();
                info.BuildingId = new Guid(b);
                info.RoomId = new Guid(r);
                info.UnitNumber = u.PadLeft(3, '0');

                c.DBAcrchive(info, User.Identity.Name);

                info.UpdateLDAP();
            }
            catch (Exception ex)
            {
                AnvilExceptionCollector ec = new AnvilExceptionCollector(ex);
                result = ec.ToUL();
            }

            return Content(result);
        }
Пример #16
0
        public ActionResult DeleteOUTemplate(Guid id)
        {
            string result = "The template was successfully deleted";

            try
            {
                OUTemplate t = DbContext.OUTemplates.Find(id);

                List<StaffFilterClause> stf = DbContext.StaffFilterClauses.Where(x => x.FilterId.Equals(t.OUId)).ToList();

                List<StudentFilterClause> stu = DbContext.StudentFilterClauses.Where(x => x.FilterId.Equals(t.OUId)).ToList();

                DbContext.StaffFilterClauses.RemoveRange(stf);
                DbContext.StudentFilterClauses.RemoveRange(stu);

                DbContext.OUTemplates.Remove(t);

                DbContext.SaveChanges();
            }
            catch (Exception ex)
            {
                AnvilExceptionCollector ec = new AnvilExceptionCollector(ex);
                result = ec.ToUL();
            }

            return Content(result, "text/html");
        }
Пример #17
0
        public ActionResult GetShares(string server)
        {
            string result = "";

            try
            {
                SharedFolderTree n = new SharedFolderTree(server);
                n.Recursive = false;

                n.Refresh();
                result = "<div class='tree'>" + n.ToUL() + "</div>";
            }
            catch(Exception ex)
            {
                AnvilExceptionCollector ec = new AnvilExceptionCollector(ex);
                result = ec.ToUL();
            }

            return Content(result);
        }
Пример #18
0
        public static void ValidateItem(object item)
        {
            var context = new ValidationContext(item, serviceProvider: null, items: null);
            var results = new List<ValidationResult>();
            var isValid = Validator.TryValidateObject(item, context, results);

            if (!isValid)
            {
                string[] comments = results.Select(x => x.ErrorMessage).ToArray();
                AnvilExceptionCollector ec = new AnvilExceptionCollector("Validation failed");
                ec.AddRange(comments);
                throw ec.ToException();
            }
        }