Exemple #1
0
        public string GetShiftId(decimal userId, string branchCode)
        {
            try
            {
                TblShift _shift = null;

                if (string.IsNullOrEmpty(branchCode))
                {
                    var branches = GetBranchesByUser(userId);
                    branchCode = branches.FirstOrDefault();
                }

                if (!IsShiftIdExists(userId, branchCode))
                {
                    var _branch = BrancheHelper.GetBranches().Where(b => b.BranchCode == branchCode).FirstOrDefault();

                    _shift = new TblShift
                    {
                        UserId     = userId,
                        Narration  = "Shift in Progress.",
                        Status     = 0,
                        EmployeeId = -1,
                        BranchId   = _branch?.BranchId,
                        BranchCode = _branch?.BranchCode,
                        BranchName = _branch?.BranchName,
                        InTime     = DateTime.Now,
                        OutTime    = DateTime.Now
                    };

                    using Repository <TblShift> _repo = new Repository <TblShift>();
                    _repo.TblShift.Add(_shift);
                    _repo.SaveChanges();
                }
                else
                {
                    //if user entry exists for today
                    using Repository <TblShift> _repo = new Repository <TblShift>();
                    _shift = _repo.TblShift
                             .AsEnumerable()
                             .Where(x => DateTime.Parse(x.InTime.Value.ToShortDateString()) == DateTime.Parse((DateTime.Today).ToShortDateString()) &&
                                    x.UserId == userId &&
                                    x.BranchCode == branchCode)
                             .FirstOrDefault();

                    _shift.OutTime   = DateTime.Now;
                    _shift.Status    = 0;
                    _shift.Narration = "Shift in Progress.";

                    _repo.TblShift.Update(_shift);
                    _repo.SaveChanges();
                }

                return(_shift.ShiftId.ToString());
            }
            catch (Exception)
            {
                //throw Exception;
                return("-1");
            }
        }
Exemple #2
0
 public List <TblBranch> GetBranches()
 {
     try
     {
         return(BrancheHelper.GetBranches());
     }
     catch { throw; }
 }
 public List <TblBranch> GetBranchesList()
 {
     try
     {
         return(BrancheHelper.GetBranches());
     }
     catch (Exception ex) { throw ex; }
 }