Example #1
0
        public long CreateUser(UserCreateViewModel userModel)
        {
            try
            {
                var tbl_Users = new tbl_Users();
                tbl_Users.GroupID        = userModel.GroupID;
                tbl_Users.UserFullName   = userModel.UserFullName;
                tbl_Users.UserEmail      = userModel.UserEmail;
                tbl_Users.UserPass       = userModel.UserPass;
                tbl_Users.UserPhone      = userModel.UserPhone;
                tbl_Users.UserCreateDate = DateTime.Now;
                tbl_Users.UserDOB        = userModel.UserDOB;
                tbl_Users.UserExtention  = userModel.UserExtention;
                tbl_Users.UserName       = userModel.UserName;
                tbl_Users.UserJoinDate   = userModel.UserJoinDate;
                tbl_Users.UserStatus     = userModel.UserStatus;
                tbl_Users.UserComputer   = userModel.UserComputer;
                tbl_Users.UserAddress    = userModel.UserAddress;


                db.tbl_Users.Add(tbl_Users);
                var result = db.SaveChanges();
                return(result);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                return(-1);
            }
        }
Example #2
0
        public int CheckCongThem(UserEventCreateViewModel modelEvent)
        {
            int result = 0;
            //int loopLength = modelEvent.UeWillExpires.Value.Day - modelEvent.UeDateExpires.Value.Day;

            var fromDate = modelEvent.UeDateExpires.Value;
            var toDate   = modelEvent.UeWillExpires.Value;
            int i        = 0;

            try
            {
                while (fromDate.Date.AddDays(i) <= toDate.Date)
                {
                    var modelAtt = new tbl_Attandance();
                    modelAtt.UserID        = modelEvent.UserID;
                    modelAtt.AtDateCheckIn = fromDate.Date.AddDays(i);
                    modelAtt.AtInOrOut     = (int)Enums.LoaiCong.ChoDuyet;
                    modelAtt.AtMonth       = fromDate.Date.AddDays(i).Month;
                    modelAtt.AtDay         = fromDate.Date.AddDays(i).Day;
                    modelAtt.AtYear        = fromDate.Date.AddDays(i).Year;
                    modelAtt.AtTime        = DateTime.Now;
                    modelAtt.AtNote        = GetDayOfWeek(fromDate.Date.AddDays(i).Year, fromDate.Date.AddDays(i).Month, fromDate.Date.AddDays(i).Day);
                    modelAtt.UeID          = modelEvent.UeID;

                    List <tbl_Attandance> liAtt = CheckDateUnique(fromDate.Date.AddDays(i), modelEvent.UserID.Value);

                    if (liAtt.Count() < 1)
                    {
                        db.tbl_Attandance.Add(modelAtt);
                        result = db.SaveChanges();
                    }
                    else
                    {
                        using (TransactionScope scope = new TransactionScope())
                        {
                            result = db.Database.ExecuteSqlCommand("exec proc_as_UpdateAttandaceWithEvent @AtID,@AtInOrOut,@UeID",
                                                                   new SqlParameter("@AtID", liAtt[0].AtID),
                                                                   new SqlParameter("@AtInOrOut", (int)Enums.LoaiCong.ChoDuyet),
                                                                   new SqlParameter("@UeID", modelEvent.UeID));
                            scope.Complete();
                        }
                    }
                    i++;
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }


            return(result);
        }
Example #3
0
        public long CreateUserEvent(UserEventCreateViewModel createModel)
        {
            var result = CheckFromDateToDate(createModel.UeDateExpires.Value, createModel.UeWillExpires.Value, createModel.UserID.Value);

            if (result == 1)
            {
                try
                {
                    var model = new tbl_UserEvent();
                    model.EventID       = createModel.EventID;
                    model.UserID        = createModel.UserID;
                    model.UeCount       = createModel.UeType; //Phep hay Cong tac
                    model.UeOk          = false;
                    model.UeCreateDate  = DateTime.Now;
                    model.UeDateExpires = createModel.UeDateExpires;
                    model.UeNote        = createModel.UeNote;
                    model.UeWillExpires = createModel.UeWillExpires;
                    model.UeCount       = createModel.UeType;

                    db.tbl_UserEvent.Add(model);
                    db.SaveChanges();

                    int UeId = model.UeID;

                    if (UeId > 0)
                    {
                        try
                        {
                            AttandanceDAL modelAtt = new AttandanceDAL();
                            createModel.UeID = model.UeID;
                            var kq = modelAtt.CheckCongThem(createModel);
                        }catch (Exception ex)
                        {
                            throw ex;
                        }
                    }
                }
                catch (Exception ex)
                {
                    throw ex;
                }
            }
            return(result);
        }