Beispiel #1
0
        public string SaveEmployeeShift(List <Int64> UserId, int Shift, DateTime FromDate, DateTime ToDate, Int64 MgrId)
        {
            try
            {
                int isSaved = 0;

                using (var context = new NLTDDbContext())
                {
                    var shiftMapping = context.ShiftMapping.Where(c => UserId.Contains(c.UserID) && (c.ShiftDate >= FromDate && c.ShiftDate <= ToDate)).ToList();
                    shiftMapping.ForEach(u =>
                    {
                        u.ShiftID      = Shift;
                        u.ModifiedBy   = MgrId;
                        u.ModifiedDate = DateTime.Now;
                    });

                    isSaved = context.SaveChanges();

                    var shiftTransaction = from id in UserId
                                           select new ShiftTransaction
                    {
                        ShiftID     = Shift,
                        UserId      = id,
                        CreatedBy   = MgrId,
                        Createddate = DateTime.Now,
                        FromDate    = FromDate,
                        ToDate      = ToDate
                    };

                    context.ShiftTransaction.AddRange(shiftTransaction);
                    isSaved = context.SaveChanges();
                }

                return(isSaved > 0 ? "Saved" : "Failed");
            }
            catch (Exception ex)
            {
                return(ex.Message);
            }
        }
Beispiel #2
0
        public string SaveShiftMaster(int shiftId, string shiftName, TimeSpan fromTime, TimeSpan toTime, Int64 mgrId)
        {
            try
            {
                int isSaved = 0;

                using (var context = new NLTDDbContext())
                {
                    var exists = context.ShiftMaster.Where(c => c.FromTime == fromTime && c.ToTime == toTime && c.ShiftID != shiftId).ToList();
                    if (exists != null && exists.Count > 0)
                    {
                        return("Shift Already Available.");
                    }
                    else
                    {
                        var objShiftMaster = context.ShiftMaster.Where(c => c.ShiftID == shiftId).SingleOrDefault();
                        if (objShiftMaster != null)
                        {
                            objShiftMaster                  = context.ShiftMaster.Where(c => c.ShiftID == shiftId).Single();
                            objShiftMaster.ShiftID          = shiftId;
                            objShiftMaster.ShiftDescription = shiftName;
                            objShiftMaster.FromTime         = fromTime;
                            objShiftMaster.ToTime           = toTime;
                        }
                        else
                        {
                            objShiftMaster = new ShiftMaster
                            {
                                ShiftDescription = shiftName,
                                FromTime         = fromTime,
                                ToTime           = toTime,
                                CreatedBy        = mgrId,
                                CreatedDate      = DateTime.Now
                            };
                        }
                        context.ShiftMaster.AddOrUpdate(objShiftMaster);
                        isSaved = context.SaveChanges();
                    }
                }

                return(isSaved > 0 ? "Saved" : "Failed");
            }
            catch (Exception ex)
            {
                return(ex.Message);
            }
        }