Beispiel #1
0
        public bool SaveSetting(List <Setting> settings, string user)
        {
            bool result = false;

            try
            {
                using (GBHODBEntities db = new GBHODBEntities())
                {
                    settings = settings.Where(x => x.Type == typeUser).ToList();
                    foreach (Setting setting in settings)
                    {
                        Setting item = db.Settings.SingleOrDefault(x => x.SettingId == setting.SettingId);
                        if (item != null)
                        {
                            item.Value        = setting.Value;
                            item.ModifiedBy   = user;
                            item.ModifiedDate = DateHelper.DateTimeNow;
                            db.SaveChanges();
                        }
                    }
                    result = true;
                }
            }
            catch
            {
                result = false;
            }

            return(result);
        }
Beispiel #2
0
        public void UpdateMemberType(int memberId, string status, string user)
        {
            using (GBHODBEntities db = new GBHODBEntities())
            {
                if (status != "approve")
                {
                    Member approver        = db.Members.First(x => x.MemberId == memberId);
                    bool   hasChildPending = db.Members.Count(x => x.RecState == "A" && x.HierarchyCode.StartsWith(approver.HierarchyCode) && x.MemberId != memberId) > 0;
                    if (hasChildPending)
                    {
                        throw new Exception("Unable to cancel approval, this member has already approved/pending downline.");
                    }
                }

                Member item = db.Members.SingleOrDefault(x => x.MemberId == memberId);
                if (item != null)
                {
                    item.Type         = status == "approve" ? "Active" : "Cancelled";
                    item.RecState     = status == "approve" ? "A" : "D";
                    item.ApprovedBy   = user;
                    item.ApprovedDate = DateHelper.DateTimeNow;
                    db.SaveChanges();
                }
            }
        }
Beispiel #3
0
        private long SaveOrder(int productId, int memberId, string currUser)
        {
            long orderId = 0;

            using (GBHODBEntities db = new GBHODBEntities())
            {
                Order order = db.Orders.Where(x => x.Status == "Pending" && x.RecState == "A" && x.MemberId == memberId).FirstOrDefault();

                if (order == null)
                {
                    order             = new Order();
                    order.MemberId    = memberId;
                    order.Status      = "Pending";
                    order.RecState    = "A";
                    order.CreatedDate = DateHelper.DateTimeNow;
                    order.CreatedBy   = currUser;
                    db.Orders.Add(order);
                }
                else
                {
                    order.ModifiedBy   = currUser;
                    order.ModifiedDate = DateHelper.DateTimeNow;
                }

                db.SaveChanges();

                orderId = order.OrderId;
            }
            return(orderId);
        }
Beispiel #4
0
        public void SubmitOrder(long orderId, List <OrderItem> cart, int orderByUserId, string orderBy, string processedBy)
        {
            using (GBHODBEntities db = new GBHODBEntities())
            {
                Order order = db.Orders.Where(x => x.OrderId == orderId).First();
                order.Status        = "Processed";
                order.ModifiedBy    = processedBy;
                order.ModifiedDate  = DateHelper.DateTimeNow;
                order.OrderDate     = DateHelper.DateTimeNow;
                order.OrderBy       = orderBy;
                order.OrderFor      = orderBy;
                order.MemberId      = orderByUserId;
                order.ProcessedBy   = processedBy;
                order.ProcessedDate = DateHelper.DateTimeNow;

                foreach (var item in cart)
                {
                    OrderItem orderItem = db.OrderItems.Where(x => x.OrderItemId == item.OrderItemId).FirstOrDefault();
                    if (orderItem != null)
                    {
                        orderItem.QTY = item.QTY;
                    }
                }

                db.SaveChanges();
            }
        }
Beispiel #5
0
 public bool Delete(int id, string currUser)
 {
     try
     {
         using (GBHODBEntities db = new GBHODBEntities())
         {
             Product item = db.Products.SingleOrDefault(x => x.ProductId == id);
             if (item != null)
             {
                 item.ModifiedBy   = currUser;
                 item.ModifiedDate = DateHelper.DateTimeNow;
                 item.RecState     = "D";
                 db.SaveChanges();
                 return(true);
             }
             else
             {
                 return(false);
             }
         }
     }
     catch
     {
         return(false);
     }
 }
Beispiel #6
0
 public void SaveMemberLastLoggedOn(int id)
 {
     using (GBHODBEntities db = new GBHODBEntities())
     {
         Member item = db.Members.SingleOrDefault(x => x.MemberId == id);
         if (item != null)
         {
             item.LastLoggedIn = DateHelper.DateTimeNow;
             db.SaveChanges();
         }
     }
 }
Beispiel #7
0
        public void RemoveOrderItem(long orderItemId)
        {
            using (GBHODBEntities db = new GBHODBEntities())
            {
                var item = (from x in db.OrderItems
                            where x.OrderItemId == orderItemId
                            select x).FirstOrDefault();

                db.OrderItems.Remove(item);
                db.SaveChanges();
            }
        }
Beispiel #8
0
        //public void ProcessOrder(long orderId, string currUser)
        //{
        //    using (GBHODBEntities db = new GBHODBEntities())
        //    {
        //        Order order = db.Orders.Where(x => x.OrderId == orderId).First();
        //        order.Status = "Processed";
        //        order.ModifiedBy = currUser;
        //        order.ModifiedDate = DateHelper.DateTimeNow;
        //        order.ProcessedBy = currUser;
        //        order.ProcessedDate = DateHelper.DateTimeNow;
        //        db.SaveChanges();
        //    }
        //}

        public void CancelOrder(long orderId, string currUser)
        {
            using (GBHODBEntities db = new GBHODBEntities())
            {
                Order order = db.Orders.Where(x => x.OrderId == orderId).First();
                order.Status        = "Cancelled";
                order.ModifiedBy    = currUser;
                order.ModifiedDate  = DateHelper.DateTimeNow;
                order.ProcessedBy   = currUser;
                order.ProcessedDate = DateHelper.DateTimeNow;
                db.SaveChanges();
            }
        }
Beispiel #9
0
        public bool Save(Product product, string currUser)
        {
            try
            {
                using (GBHODBEntities db = new GBHODBEntities())
                {
                    Product item = db.Products.SingleOrDefault(x => x.ProductId == product.ProductId);

                    if (item == null)
                    {
                        item = new Product();
                    }

                    item.ProductName = product.ProductName;
                    item.Description = product.Description;
                    item.Amount      = product.Amount;
                    item.Points      = product.Points;

                    if (!string.IsNullOrEmpty(product.Picture))
                    {
                        item.Picture = product.Picture;
                    }

                    if (item.ProductId == 0)
                    {
                        item.RecState    = "A";
                        item.CreatedDate = DateHelper.DateTimeNow;
                        item.CreatedBy   = currUser;
                        db.Products.Add(item);
                    }
                    else
                    {
                        item.ModifiedBy   = currUser;
                        item.ModifiedDate = DateHelper.DateTimeNow;
                    }

                    db.SaveChanges();
                }

                return(true);
            }
            catch
            {
                return(false);
            }
        }
Beispiel #10
0
        public string ChangePassword(int memberId, string newPWD, string confirmPWD)
        {
            string e_newPWD     = EncryptionManager.encrypt(newPWD);
            string e_confirmPWD = EncryptionManager.encrypt(confirmPWD);

            using (GBHODBEntities db = new GBHODBEntities())
            {
                //validate new and confirm password
                if (e_newPWD == e_confirmPWD)
                {
                    //validate old password
                    int checkOld = db.Members.Count(x => x.MemberId == memberId);
                    if (checkOld > 0)
                    {
                        //validate new password is unique
                        int checkUnique = db.Members.Count(x => x.MemberId == memberId && x.Password != e_newPWD);
                        if (checkUnique > 0)
                        {
                            Member item = db.Members.SingleOrDefault(x => x.MemberId == memberId);
                            item.Password = e_newPWD;
                            db.SaveChanges();
                            return(string.Empty);
                        }
                        else
                        {
                            return("PasswordErrorMsg2");
                        }
                    }
                    else
                    {
                        return("PasswordErrorMsg1");
                    }
                }
                else
                {
                    return("PasswordErrorMsg1");
                }
            }
        }
Beispiel #11
0
        public void AddToCart(int productId, int memberId, string currUser)
        {
            long orderId = SaveOrder(productId, memberId, currUser);

            using (GBHODBEntities db = new GBHODBEntities())
            {
                Product   product   = db.Products.Where(x => x.ProductId == productId).FirstOrDefault();
                OrderItem orderItem = db.OrderItems.Where(x => x.ProductId == productId && x.OrderId == orderId).FirstOrDefault();

                if (orderItem == null)
                {
                    orderItem           = new OrderItem();
                    orderItem.OrderId   = orderId;
                    orderItem.ProductId = productId;
                    orderItem.Amount    = product.Amount;
                    orderItem.QTY       = 1;
                    orderItem.Points    = product.Points;
                    db.OrderItems.Add(orderItem);
                    db.SaveChanges();
                }
            }
        }
Beispiel #12
0
        public int SaveMember(Member member, string currUser)
        {
            int memberId = member.MemberId;

            using (GBHODBEntities db = new GBHODBEntities())
            {
                #region validate member code (hidden)
                ////validate member code
                //bool isCodeExists = db.Members.Count(x => x.MemberId != member.MemberId && x.MemberCode == member.MemberCode && x.RecState == "A") > 0;
                //if (isCodeExists)
                //{
                //    throw new Exception("Member ID already exists. Please enter a different member ID.");
                //}
                //else
                //{

                //}
                #endregion

                //validate username
                bool isUsernameExists = db.Members.Count(x => x.MemberId != member.MemberId && x.Username == member.Username && x.RecState == "A") > 0;
                if (isUsernameExists)
                {
                    throw new Exception("User name ID already exists. Please enter a different user name");
                }
                else
                {
                    // validate placement
                    bool   isPlaceExists = false;
                    string hCode         = string.Empty;
                    if (member.ParentId > 0)
                    {
                        string parentHCode = db.Members.SingleOrDefault(x => x.MemberId == member.ParentId).HierarchyCode;
                        hCode         = parentHCode + member.HierarchyCode.Substring(member.HierarchyCode.Length - 1, 1);
                        isPlaceExists = db.Members.Count(x => x.MemberId != member.MemberId && x.HierarchyCode == hCode && x.RecState == "A") > 0;
                    }
                    if (isPlaceExists)
                    {
                        throw new Exception("Selected placement/group is already occupied. Please enter a different placement/group.");
                    }
                    else
                    {
                        int    lastId = db.Members.OrderByDescending(x => x.MemberId).First().MemberId;
                        Member item   = db.Members.SingleOrDefault(x => x.MemberId == member.MemberId);

                        if (item == null)
                        {
                            item = new Member();
                        }

                        item.Code              = member.Code;
                        item.Username          = member.Username;
                        item.FirstName         = member.FirstName;
                        item.MiddleName        = member.MiddleName;
                        item.LastName          = member.LastName;
                        item.Email             = member.Email;
                        item.MobileNo          = member.MobileNo;
                        item.TelephoneNo       = member.TelephoneNo;
                        item.Occupation        = member.Occupation;
                        item.Birthday          = member.Birthday;
                        item.BirthPlace        = member.BirthPlace;
                        item.Citizenship       = member.Citizenship;
                        item.Gender            = member.Gender;
                        item.MaritalStatus     = member.MaritalStatus;
                        item.PresentAddress    = member.PresentAddress;
                        item.ProvincialAddress = member.ProvincialAddress;
                        item.ParentId          = member.ParentId;
                        item.SponsorId         = member.SponsorId;
                        item.PaymentType       = member.PaymentType;
                        item.CashNote          = member.CashNote;
                        item.BankBranch        = member.BankBranch;
                        item.DepositNo         = member.DepositNo;
                        item.DateDeposited     = member.DateDeposited;

                        if (!string.IsNullOrEmpty(hCode))
                        {
                            item.HierarchyCode = hCode;
                        }

                        item.RoleId        = member.RoleId;
                        item.IsFreeAccount = member.IsFreeAccount;

                        if (member.Picture != null)
                        {
                            item.Picture = member.Picture;
                        }

                        if (item.MemberId == 0)
                        {
                            item.MemberCode  = String.Format("M-{0:D8}", lastId + 1);
                            item.Password    = member.Password;
                            item.Type        = MemberTypeEnum.ForValidate.ToString();
                            item.CreatedDate = DateHelper.DateTimeNow;
                            item.CreatedBy   = currUser;
                            item.DateJoined  = DateHelper.DateTimeNow;
                            item.RecState    = "A";
                            db.Members.Add(item);
                        }
                        else
                        {
                            item.ModifiedBy   = currUser;
                            item.ModifiedDate = DateHelper.DateTimeNow;
                        }

                        db.SaveChanges();
                        memberId = item.MemberId;
                    }
                }
            }

            return(memberId);
        }