Ejemplo n.º 1
0
 public PersonInfo Find(Guid id)
 {
     using (FusionFaceDb db = new FusionFaceDb())
     {
         return(db.People.Where(p => p.ID == id)
                .Select(p => new PersonInfo()
         {
             ID = p.ID,
             Fullname = p.Fullname,
             IdentityNumber = p.IdentityNumber,
             Nationality = p.Nationality,
             PhoneNumber = p.PhoneNumber,
             Address = p.Address,
             Company = p.Company,
             Dob = p.DOB,
             Status = p.Status,
             CreatedAt = p.CreatedAt,
             ModifiedAt = p.ModifiedAt,
             Photos = p.Photos.Where(i => !i.IsDeleted).Select(i => new PhotoInfo()
             {
                 ID = i.ID
             }).ToList()
         }
                        ).FirstOrDefault());
     }
 }
Ejemplo n.º 2
0
 public byte[] GetPhotoData(Guid id)
 {
     using (FusionFaceDb db = new FusionFaceDb())
     {
         return(db.Photos.Where(p => p.ID == id).Select(p => p.Data).FirstOrDefault());
     }
 }
Ejemplo n.º 3
0
        public SearchResult SearchReportA(SearchInfo searchInfo)
        {
            if (searchInfo.search.value == null)
            {
                searchInfo.search.value = "";
            }

            string keyword = searchInfo.search.value;

            using (FusionFaceDb db = new FusionFaceDb())
            {
                var q = (from u in db.UserMasters
                         where (u.Username.Contains(keyword) ||
                                u.Fullname.Contains(keyword)) &&
                         !u.IsDeleted
                         select new UserInfo()
                {
                    ID = u.ID,
                    Username = u.Username,
                    Email = u.Email,
                    Status = u.Status,
                    Fullname = u.Fullname
                });

                int total = q.Count();



                if (searchInfo.order != null && searchInfo.order.Length > 0)
                {
                    string orderBy   = "";
                    bool   orderDesc = false;

                    orderBy   = searchInfo.columns[searchInfo.order[0].column].data;
                    orderDesc = searchInfo.order[0].dir == "desc";

                    q = q.OrderByDynamic(orderBy, orderDesc);
                }
                else
                {
                    q = q.OrderBy(x => x.Username);
                }

                List <UserInfo> users = q.Skip(searchInfo.start).Take(searchInfo.length).ToList();

                SearchResult result = new SearchResult()
                {
                    draw            = searchInfo.draw,
                    recordsTotal    = total,
                    recordsFiltered = total,
                    data            = users.ToArray()
                };

                return(result);
            }
        }
Ejemplo n.º 4
0
 public bool DeletePhoto(Guid id)
 {
     using (FusionFaceDb db = new FusionFaceDb())
     {
         Photo photo = db.Photos.Where(p => p.ID == id).FirstOrDefault();
         photo.IsDeleted = true;
         db.SaveChanges();
         return(true);
     }
 }
Ejemplo n.º 5
0
 public PhotoInfo GetPhoto(Guid id)
 {
     using (FusionFaceDb db = new FusionFaceDb())
     {
         return(db.Photos.Where(p => p.ID == id).Select(p => new PhotoInfo()
         {
             ID = p.ID, PersonID = p.PersonID
         }).FirstOrDefault());
     }
 }
Ejemplo n.º 6
0
        public DashboardSummaryInfo GetDashboardSummary()
        {
            using (FusionFaceDb db = new FusionFaceDb())
            {
                DashboardSummaryInfo info = new DashboardSummaryInfo();
                info.TotalUsers      = db.UserMasters.Where(u => u.Status == "ACTIVE").Count();
                info.TotalPeople     = db.People.Where(u => u.Status == "ACTIVE").Count();
                info.TotalActivities = db.TransactionSummaries.Sum(i => i.Total);
                info.LastLoginString = FusionAppContext.Current.User.LastLogin.HasValue ?
                                       FusionAppContext.Current.User.LastLogin.Value.ToString("yyyy-MM-dd HH:mm:ss") : "";

                return(info);
            }
        }
Ejemplo n.º 7
0
        public SearchResult Search(SearchInfo searchInfo)
        {
            if (searchInfo.search.value == null)
            {
                searchInfo.search.value = "";
            }

            string keyword = searchInfo.search.value;

            using (FusionFaceDb db = new FusionFaceDb())
            {
                var q = (from u in db.People
                         where (u.Fullname.Contains(keyword) ||
                                u.IdentityNumber.Contains(keyword) ||
                                u.Nationality.Contains(keyword) ||
                                u.Company.Contains(keyword)) &&
                         !u.IsDeleted
                         select new PersonInfo()
                {
                    ID = u.ID,
                    Fullname = u.Fullname,
                    IdentityNumber = u.IdentityNumber,
                    Dob = u.DOB,
                    Company = u.Company,
                    Nationality = u.Nationality,
                    PhoneNumber = u.PhoneNumber,
                    Address = u.Address,
                    Status = u.Status,
                    CreatedAt = u.CreatedAt,
                    ModifiedAt = u.ModifiedAt
                });

                int total = q.Count();



                if (searchInfo.order != null && searchInfo.order.Length > 0)
                {
                    string orderBy   = "";
                    bool   orderDesc = false;

                    orderBy   = searchInfo.columns[searchInfo.order[0].column].data;
                    orderDesc = searchInfo.order[0].dir == "desc";

                    q = q.OrderByDynamic(orderBy, orderDesc);
                }
                else
                {
                    q = q.OrderBy(x => x.Fullname);
                }

                List <PersonInfo> persons = q.Skip(searchInfo.start).Take(searchInfo.length).ToList();

                SearchResult result = new SearchResult()
                {
                    draw            = searchInfo.draw,
                    recordsTotal    = total,
                    recordsFiltered = total,
                    data            = persons.ToArray()
                };

                return(result);
            }
        }
Ejemplo n.º 8
0
        public SearchResult SearchReportTransaction(SearchInfo searchInfo)
        {
            if (searchInfo.search.value == null)
            {
                searchInfo.search.value = "";
            }

            string   keyword      = searchInfo.search.value;
            bool     dateFiltered = false;
            DateTime startDate    = DateTime.MinValue;
            DateTime endDate      = DateTime.MaxValue;

            if (searchInfo.search.fields != null && searchInfo.search.fields.Length >= 2)
            {
                try
                {
                    int iStartDate = Array.IndexOf(searchInfo.search.fields, "startDate");
                    startDate = DateTime.ParseExact(searchInfo.search.values[iStartDate], "yyyy-MM-dd", null);

                    int iEndDate = Array.IndexOf(searchInfo.search.fields, "endDate");
                    endDate = DateTime.ParseExact(searchInfo.search.values[iEndDate], "yyyy-MM-dd", null);
                    endDate = endDate.AddDays(1);

                    dateFiltered = endDate >= startDate;
                }
                catch { }
            }


            using (FusionFaceDb db = new FusionFaceDb())
            {
                var q = (from u in db.TransactionMasters
                         where (u.TranxType.Contains(keyword) ||
                                u.ObjectID.Contains(keyword))
                         select new TransactionInfo()
                {
                    ID = u.ID,
                    TranxType = u.TranxType,
                    ObjectID = u.ObjectID,
                    ObjectName = u.ObjectName,
                    RecordedDate = u.RecordedDate,
                    ClientID = u.ClientID
                });

                if (dateFiltered)
                {
                    q = q.Where(t => t.RecordedDate >= startDate && t.RecordedDate < endDate);
                }

                int total = q.Count();


                if (searchInfo.order != null && searchInfo.order.Length > 0)
                {
                    string orderBy   = "";
                    bool   orderDesc = false;

                    orderBy   = searchInfo.columns[searchInfo.order[0].column].data;
                    orderDesc = searchInfo.order[0].dir == "desc";

                    q = q.OrderByDynamic(orderBy, orderDesc);
                }
                else
                {
                    q = q.OrderByDescending(x => x.RecordedDate);
                }

                List <TransactionInfo> list = q.Skip(searchInfo.start).Take(searchInfo.length).ToList();

                SearchResult result = new SearchResult()
                {
                    draw            = searchInfo.draw,
                    recordsTotal    = total,
                    recordsFiltered = total,
                    data            = list.ToArray()
                };

                return(result);
            }
        }
Ejemplo n.º 9
0
        public SearchResult SearchReportTransactionSummary(SearchInfo searchInfo)
        {
            if (searchInfo.search.value == null)
            {
                searchInfo.search.value = "";
            }

            string   keyword      = searchInfo.search.value;
            bool     dateFiltered = false;
            DateTime startDate    = DateTime.MinValue;
            DateTime endDate      = DateTime.MaxValue;

            if (searchInfo.search.fields != null && searchInfo.search.fields.Length >= 2)
            {
                try
                {
                    int iStartDate = Array.IndexOf(searchInfo.search.fields, "startDate");
                    startDate = DateTime.ParseExact(searchInfo.search.values[iStartDate], "yyyy-MM-dd", null);

                    int iEndDate = Array.IndexOf(searchInfo.search.fields, "endDate");
                    endDate = DateTime.ParseExact(searchInfo.search.values[iEndDate], "yyyy-MM-dd", null);
                    endDate = endDate.AddDays(1);

                    dateFiltered = endDate >= startDate;
                }
                catch { }
            }

            using (FusionFaceDb db = new FusionFaceDb())
            {
                var q = (from d in db.DateMasters
                         join u in db.TransactionSummaries on d.DateID equals u.RecordedDate into ux
                         from u in ux.DefaultIfEmpty()
                         where d.DateID >= startDate && d.DateID < endDate
                         select new TransactionSummaryInfo()
                {
                    TranxType = (u != null) ? u.TranxType : "PREDICT",
                    RecordedDate = d.DateID,
                    ClientID = (u != null) ? u.ClientID : "AA",
                    Total = (u != null) ? u.Total : 0
                });

                int total = q.Count();

                List <TransactionSummaryInfo> list = q.ToList();

                List <DateTime> dates = list.Select(u => u.RecordedDate).Distinct().ToList();

                foreach (DateTime date in dates)
                {
                    if (list.Where(u => u.RecordedDate == date).Count() < 2)
                    {
                        if (list.Where(u => u.RecordedDate == date).FirstOrDefault().TranxType == "PREDICT")
                        {
                            list.Add(new TransactionSummaryInfo()
                            {
                                TranxType = "REGISTER", RecordedDate = date, Total = 0, ClientID = "AA"
                            });
                        }
                        else
                        {
                            list.Add(new TransactionSummaryInfo()
                            {
                                TranxType = "PREDICT", RecordedDate = date, Total = 0, ClientID = "AA"
                            });
                        }
                    }
                }

                list = list.OrderBy(u => u.RecordedDate).ThenBy(u => u.TranxType).ToList();

                SearchResult result = new SearchResult()
                {
                    draw            = searchInfo.draw,
                    recordsTotal    = total,
                    recordsFiltered = total,
                    data            = list.ToArray()
                };

                return(result);
            }
        }
Ejemplo n.º 10
0
        /// <summary>
        /// To Validate Login and return UserProfile for Authorization
        /// </summary>
        /// <param name="loginInfo"></param>
        /// <returns></returns>
        public UserProfile Authenticate(LoginInfo loginInfo)
        {
            UserProfile result = null;

            if (!string.IsNullOrEmpty(loginInfo.Password) &&
                !string.IsNullOrEmpty(loginInfo.Username))
            {
                string hashedPassword = Hash(loginInfo.Password);

                using (FusionFaceDb db = new FusionFaceDb())
                {
                    DateTime now = DateTime.Now;

                    var q = from u in db.UserMasters
                            where u.Username == loginInfo.Username &&
                            u.Password == hashedPassword &&
                            !u.IsDeleted &&
                            (u.AccountBlockedExpiry == null || u.AccountBlockedExpiry > now)
                            select u;

                    if (q.Count() > 0)
                    {
                        UserMaster uMaster = q.First();



                        result = new UserProfile()
                        {
                            ID        = uMaster.ID,
                            Username  = uMaster.Username,
                            LastLogin = uMaster.LastLoginTime
                        };

                        //Record LastLoginTime
                        uMaster.LastLoginTime    = DateTime.Now;
                        uMaster.PasswordTryCount = 0;

                        db.SaveChanges();

                        #region Permissions
                        var z = from ur in db.UserGroups
                                join p in db.Permissions on ur.GroupID equals p.GroupID
                                where ur.UserID == uMaster.ID
                                select p;

                        if (z.Count() > 0)
                        {
                            List <Permission> permissions = z.Distinct().ToList();

                            foreach (Permission p in permissions)
                            {
                                if (!result.Permissions.Contains(p.FunctionID))
                                {
                                    result.Permissions.Add(p.FunctionID);
                                }
                            }
                        }
                        #endregion

                        #region Menus
                        result.Menus.AddRange(GetMenuItemList(result.Permissions));
                        #endregion

                        #region Roles
                        var gr = from ur in db.UserGroups
                                 join g in db.GroupMasters on ur.GroupID equals g.ID
                                 where ur.UserID == uMaster.ID
                                 select g;

                        if (gr.Count() > 0)
                        {
                            List <GroupMaster> groups = gr.Distinct().ToList();

                            foreach (GroupMaster grp in groups)
                            {
                                if (!result.Roles.Contains(grp.Name))
                                {
                                    result.Roles.Add(grp.Name);
                                }
                            }
                        }
                        #endregion
                    }
                    else
                    {
                    }
                }
            }

            return(result);
        }
Ejemplo n.º 11
0
        public List <MenuItem> GetMenuItemList(List <string> functionCodes)
        {
            List <MenuItem> result = new List <MenuItem>();

            if (functionCodes != null &&
                functionCodes.Count() > 0)
            {
                using (FusionFaceDb db = new FusionFaceDb())
                {
                    var q = from m in db.MenuMasters
                            where (functionCodes.Contains(m.FunctionID) ||
                                   m.FunctionID == null) &&
                            m.Enabled
                            orderby m.Position
                            select new MenuInfo()
                    {
                        ID          = m.ID.ToString(),
                        Name        = m.Name,
                        Description = m.Description,
                        FunctionID  = m.FunctionID,
                        Icon        = m.Icon,
                        ParentID    = m.ParentID.HasValue ? m.ParentID.ToString() : "",
                        Position    = m.Position,
                        Url         = m.Url
                    };

                    List <MenuInfo> menus = q.ToList();

                    if (menus != null &&
                        menus.Count() > 0)
                    {
                        List <MenuItem> newMenus =
                            menus.Where(m => m.ParentID == null || m.ParentID == "")
                            .Select(m => new MenuItem()
                        {
                            Info = m
                        })
                            .OrderBy(m => m.Info.Position)
                            .ToList();

                        result.AddRange(newMenus);

                        while (newMenus.Count() > 0)
                        {
                            MenuItem currentItem = newMenus.First();
                            newMenus.Remove(currentItem);

                            currentItem.Children.AddRange(
                                menus.Where(m => m.ParentID == currentItem.Info.ID)
                                .Select(m => new MenuItem()
                            {
                                Info = m, Parent = currentItem
                            })
                                .OrderBy(m => m.Info.Position)
                                .ToList()
                                );

                            newMenus.AddRange(currentItem.Children);
                        }
                    }
                }

                result.RemoveAll(m => m.Parent != null && !m.Children.Any());
            }

            return(result);
        }