Example #1
0
        public IActionResult Edit(vmShift vmShift)
        {
            if (ModelState.IsValid)
            {
                Shift shift = db.Shift.GetFirstOrDefault(s => s.Id == vmShift.Id);
                shift.Name    = vmShift.Name;
                shift.LunchHr = vmShift.LunchHr;
                db.Shift.Update(shift);
                db.Save();

                foreach (var items in vmShift.vmShiftDetails)
                {
                    ShiftDetails shiftDetails = db.ShiftDetails.GetFirstOrDefault(s => s.Id == items.Id);
                    shiftDetails.DayName         = items.DayName;
                    shiftDetails.Flag            = items.Flag;
                    shiftDetails.OfficeStartTime = items.OfficeStartTime;
                    shiftDetails.OfficeEndTime   = items.OfficeEndTime;
                    shiftDetails.CheckInTime     = items.CheckInTime;
                    shiftDetails.CheckOutTime    = items.CheckOutTime;
                    db.ShiftDetails.Update(shiftDetails);
                    db.Save();
                }
                return(Json("Success"));
                //return PartialView("_Edit", vmShift);
            }
            return(Json("Success"));
        }
Example #2
0
        public IActionResult Create(vmShift vmShift)
        {
            if (ModelState.IsValid)
            {
                Shift shift = new Shift
                {
                    Name      = vmShift.Name,
                    LunchHr   = vmShift.LunchHr,
                    IsActive  = true,
                    IsDeleted = false
                };
                db.Shift.Add(shift);
                db.Save();

                foreach (var sDetails in vmShift.vmShiftDetails)
                {
                    ShiftDetails shiftDetails = new ShiftDetails {
                        DayName         = sDetails.DayName,
                        Flag            = sDetails.Flag,
                        CheckInTime     = sDetails.CheckInTime,
                        CheckOutTime    = sDetails.CheckOutTime,
                        OfficeStartTime = sDetails.OfficeStartTime,
                        OfficeEndTime   = sDetails.OfficeEndTime,
                        ShiftId         = shift.Id
                    };
                    db.ShiftDetails.Add(shiftDetails);
                    db.Save();
                }
                return(PartialView("Create"));
            }
            return(PartialView("Create"));
        }
Example #3
0
        private static HttpResponseMessage ClientPostRequest(string RequestURI, ShiftDetails sDetails)
        {
            HttpClient client = new HttpClient();

            client.BaseAddress = new Uri("http://epmschatbotapi.azurewebsites.net");
            client.DefaultRequestHeaders.Accept.Clear();
            client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
            HttpResponseMessage response = client.PostAsJsonAsync(RequestURI, sDetails).Result;

            return(response);
        }
Example #4
0
        public ReturnResult ApplyShiftAssignmentChanges(IList <ShiftAssignmentChanges> request)
        {
            var returnResult = new ReturnResult();

            request.ToList().ForEach(item =>
            {
                if (item.IsAssigned)
                {
                    var shiftAssignmentChange = new ShiftDetails {
                        Id = 0, IsActive = true, GateID = item.GateId, ShiftDate = item.ShiftDate, ShiftID = item.ShiftId, SecurityID = item.UserId
                    };
                    _genericService.ShiftDetails.Insert(shiftAssignmentChange);
                }
                else
                {
                    var shiftAssignmentChange = _genericService.ShiftDetails.GetAll()
                                                .FirstOrDefault(item_db => item_db.ShiftID == item.ShiftId && item_db.SecurityID == item.UserId &&
                                                                item_db.ShiftDate == item.ShiftDate && item_db.IsActive
                                                                );

                    var shiftAssignmentChangeLst = _genericService.ShiftDetails.GetAll()
                                                   .Where(item_db => item_db.ShiftID == item.ShiftId && item_db.SecurityID == item.UserId && item_db.IsActive
                                                          );

                    if (shiftAssignmentChangeLst != null)
                    {
                        if (shiftAssignmentChangeLst.Count() == 1)
                        {
                            var shiftAssignmentObj = _genericService.ShitfAssignment.GetAll().FirstOrDefault(item_db => item_db.ShitfId == shiftAssignmentChange.ShiftID &&
                                                                                                             item_db.UserId == shiftAssignmentChange.SecurityID && item_db.IsActive);

                            if (shiftAssignmentObj != null)
                            {
                                shiftAssignmentObj.IsActive = false;
                                _genericService.ShitfAssignment.Update(shiftAssignmentObj);
                            }
                        }
                    }


                    if (shiftAssignmentChange != null)
                    {
                        shiftAssignmentChange.IsActive = false;
                        _genericService.ShiftDetails.Update(shiftAssignmentChange);
                    }
                }
            });

            _genericService.Commit();
            returnResult.Success = true;
            return(returnResult);
        }
Example #5
0
        static string BookTimeSheet(string empCode, string monthName, string strShift, string strstarttime, string strendtime)
        {
            string       responseString = "";
            ShiftDetails sDetails       = new ShiftDetails()
            {
                EmpCode = empCode, monthName = monthName, shift = strShift, Starttime = strstarttime, Endtime = strendtime
            };
            HttpResponseMessage responsePostMethod = ClientPostRequest("api/Shift/BookShift/", sDetails);

            if (responsePostMethod.IsSuccessStatusCode)
            {
                responseString = responsePostMethod.Content.ReadAsStringAsync().Result;
            }
            return(responseString);
        }
    public static string updatedShift(ShiftDetails detail)
    {
        string config =
            Convert.ToString(ConfigurationManager.ConnectionStrings["dbcon"]);

        List <ShiftDetails> ShiftDetails = new List <ShiftDetails>();

        SqlConnection con = new SqlConnection(config);

        con.Open();

        using (
            SqlCommand cmd =
                new SqlCommand("update Endorsement_UnitsDashboard set Unit_name=@Unit_name, Shift=@Shift, Total_Census=@Total_Census, Received=@Received, Shift_date=@Shift_date, Transfer_In=@Transfer_In, Transfer_Out=@Transfer_Out, Admission=@Admission, Endorsing_ChargeNurse_id=@Endorsing_ChargeNurse_id, Receive_ChargeNurse_id=@Receive_ChargeNurse_id where ID = @ID;",
                               con)
            )
        {
            cmd.Parameters.AddWithValue("@id", detail.id);
            cmd.Parameters.AddWithValue("@Unit_name", detail.Unit_name);
            cmd.Parameters.AddWithValue("@Shift", detail.Shift);
            cmd.Parameters.AddWithValue("@Total_Census", detail.Total_Census);
            cmd.Parameters.AddWithValue("@Received", detail.Received);
            cmd.Parameters.AddWithValue("@Shift_date", detail.Shift_date);
            cmd.Parameters.AddWithValue("@Transfer_In", detail.Transfer_In);
            cmd.Parameters.AddWithValue("@Transfer_Out", detail.Transfer_Out);
            cmd.Parameters.AddWithValue("@Admission", detail.Admission);

            cmd
            .Parameters
            .AddWithValue("@Endorsing_ChargeNurse_id",
                          detail.Endorsing_ChargeNurse_id);
            cmd
            .Parameters
            .AddWithValue("@Receive_ChargeNurse_id",
                          detail.Receive_ChargeNurse_id);

            cmd.ExecuteNonQuery();
        }

        con.Close();

        return(JsonConvert.SerializeObject(ShiftDetails));
    }
        public ActionResult Edit(IEnumerable <tblshiftdetail> tblp, int ShiftMethod = 0)
        {
            if ((Session["UserId"] == null) || (Session["UserId"].ToString() == String.Empty))
            {
                return(RedirectToAction("Login", "Login", null));
            }
            ViewBag.Logout = Session["Username"];
            ViewBag.roleid = Session["RoleID"];
            String Username = Session["Username"].ToString();
            int    UserID   = Convert.ToInt32(Session["UserID"]);

            var shiftmethodiddata = db.tblshiftmethods.Where(m => m.IsDeleted == 0 && m.ShiftMethodID == ShiftMethod).SingleOrDefault();
            int noofshifts        = shiftmethodiddata.NoOfShifts;
            int rowscount         = 0;

            //insert isedited and other details into old rows and insert the new rows.
            var shiftDetailsData = db.tblshiftdetails.Where(m => m.IsDeleted == 0 && m.ShiftMethodID == ShiftMethod).ToList();
            //check if shift method is in use or was used and now its being modified.
            ShiftDetails sd            = new ShiftDetails();
            int          shiftmethodid = Convert.ToInt32(ShiftMethod);
            bool         tick          = sd.IsThisShiftMethodIsInActionOrEnded(shiftmethodid);

            try
            {
                foreach (var shift in tblp)
                {
                    if (rowscount < noofshifts)
                    {
                        using (i_facility_tsalEntities db3 = new i_facility_tsalEntities())
                        {
                            // calculate duration
                            int      duration          = 0;
                            string   starttimestring   = "2016-06-02" + " " + shift.ShiftStartTime;
                            DateTime starttimedatetime = Convert.ToDateTime(starttimestring);
                            string   endtimestring     = null;

                            TimeSpan tsStart = (System.TimeSpan)shift.ShiftStartTime;
                            TimeSpan tsEnd   = (System.TimeSpan)shift.ShiftEndTime;

                            int result = TimeSpan.Compare(tsStart, tsEnd);
                            if (result < 0)
                            {
                                endtimestring = "2016-06-02" + " " + shift.ShiftEndTime;
                            }
                            else if (result > 0)
                            {
                                endtimestring = "2016-06-03" + " " + shift.ShiftEndTime;
                                shift.NextDay = 1;
                            }
                            DateTime endtimedatetime = Convert.ToDateTime(endtimestring);
                            TimeSpan ts = endtimedatetime.Subtract(starttimedatetime);
                            duration = Convert.ToInt32(ts.TotalMinutes);

                            if (tick)
                            {
                                //create new object/row
                                int      shiftid      = shift.ShiftDetailsID;
                                int      oldcreatedby = 0;
                                DateTime oldcreatedon = DateTime.Now;
                                using (i_facility_tsalEntities db1 = new i_facility_tsalEntities())
                                {
                                    var getShiftId = db1.tblshiftdetails.Where(m => m.IsDeleted == 0 && m.ShiftDetailsID == shiftid).SingleOrDefault();
                                    getShiftId.IsShiftDetailsEdited   = 1;
                                    getShiftId.IsDeleted              = 1;
                                    getShiftId.ShiftMethodID          = ShiftMethod;
                                    getShiftId.ShiftDetailsEditedDate = DateTime.Now;

                                    oldcreatedon        = Convert.ToDateTime(getShiftId.CreatedOn);
                                    oldcreatedby        = Convert.ToInt32(getShiftId.CreatedBy);
                                    ViewBag.ShiftMethod = new SelectList(db.tblshiftmethods.Where(m => m.IsDeleted == 0), "ShiftMethodID", "ShiftMethodName", shift.ShiftMethodID);

                                    db1.Entry(getShiftId).State = EntityState.Modified;
                                    db1.SaveChanges();
                                }
                                tblshiftdetail tsd = new tblshiftdetail();
                                tsd.Duration         = duration;
                                tsd.IsDeleted        = 0;
                                tsd.CreatedBy        = oldcreatedby;
                                tsd.CreatedOn        = oldcreatedon;
                                tsd.ModifiedBy       = UserID;
                                tsd.ModifiedOn       = DateTime.Now;
                                tsd.IsDeleted        = 0;
                                tsd.NextDay          = shift.NextDay;
                                tsd.ShiftMethodID    = ShiftMethod;
                                tsd.ShiftDetailsDesc = shift.ShiftDetailsName;
                                tsd.ShiftDetailsName = shift.ShiftDetailsDesc;
                                tsd.ShiftEndTime     = shift.ShiftEndTime;
                                tsd.ShiftStartTime   = shift.ShiftStartTime;
                                db.tblshiftdetails.Add(tsd);
                                db.SaveChanges();
                            }
                            else
                            {
                                //create new object/row
                                shift.ModifiedBy    = UserID;
                                shift.ModifiedOn    = DateTime.Now;
                                shift.Duration      = duration;
                                shift.IsDeleted     = 0;
                                shift.ShiftMethodID = ShiftMethod;

                                db3.Entry(shift).State = EntityState.Modified;
                                db3.SaveChanges();
                            }
                        }
                    }
                    rowscount++;
                }
            }
            catch (Exception e)
            {
                ViewBag.ShiftMethod = new SelectList(db.tblshiftmethods.Where(m => m.IsDeleted == 0), "ShiftMethodID", "ShiftMethodName", ShiftMethod);
                return(View(tblp));
            }
            return(RedirectToAction("Index"));
        }
Example #8
0
        public ReturnResult SaveShiftAssignment([FromBody] ShiftAssignmentVM ShitfAssignment)
        {
            bool   success       = false;
            string Message       = "";
            string currentUserId = HttpContext.Current.User.Identity.GetUserId();

            if (ShitfAssignment.Id == 0)
            {
                ShitfAssignment.FromDate = DateTime.ParseExact(ShitfAssignment.strFromDate, "dd/MM/yyyy", null);
                ShitfAssignment.ToDate   = DateTime.ParseExact(ShitfAssignment.strToDate, "dd/MM/yyyy", null);

                var data = _genericService.ShitfAssignment.GetAll().Where(x => (x.FromDate >= ShitfAssignment.FromDate &&
                                                                                x.ToDate <= ShitfAssignment.ToDate ||
                                                                                x.FromDate >= ShitfAssignment.FromDate &&
                                                                                x.FromDate <= ShitfAssignment.ToDate ||
                                                                                x.ToDate >= ShitfAssignment.FromDate &&
                                                                                x.ToDate <= ShitfAssignment.ToDate ||
                                                                                x.FromDate <= ShitfAssignment.ToDate &&
                                                                                x.ToDate >= ShitfAssignment.FromDate) && (x.UserId == ShitfAssignment.UserId) && x.IsActive && (x.ShitfId == ShitfAssignment.ShitfId)).AsQueryable();

                if (data.Count() == 0)
                {
                    ShitfAssignment obj           = new Data.Model.Entities.ShitfAssignment();
                    ShiftDetails    _shiftDetails = null;

                    obj.ShitfId    = ShitfAssignment.ShitfId;
                    obj.UserId     = ShitfAssignment.UserId;
                    obj.GateId     = ShitfAssignment.GateId;
                    obj.FromDate   = ShitfAssignment.FromDate;
                    obj.ToDate     = ShitfAssignment.ToDate;
                    obj.BuildingId = ShitfAssignment.BuildingId;
                    obj.FromDate   = DateTime.ParseExact(ShitfAssignment.strFromDate, "dd/MM/yyyy", System.Globalization.CultureInfo.InvariantCulture); //Convert.ToDateTime(ShitfAssignment.strFromDate);
                    obj.ToDate     = DateTime.ParseExact(ShitfAssignment.strToDate, "dd/MM/yyyy", System.Globalization.CultureInfo.InvariantCulture);   //Convert.ToDateTime(ShitfAssignment.strToDate);
                    obj.IsActive   = true;
                    _genericService.ShitfAssignment.Insert(obj);



                    for (DateTime startDate = ShitfAssignment.FromDate.Date; startDate <= ShitfAssignment.ToDate.Date; startDate = startDate.AddDays(1))
                    {
                        _shiftDetails            = new Data.Model.Entities.ShiftDetails();
                        _shiftDetails.ShiftID    = ShitfAssignment.ShitfId;
                        _shiftDetails.SecurityID = ShitfAssignment.UserId;
                        _shiftDetails.ShiftDate  = startDate;
                        _shiftDetails.GateID     = ShitfAssignment.GateId;
                        _shiftDetails.IsActive   = true;
                        _genericService.ShiftDetails.Insert(_shiftDetails);
                    }

                    _genericService.Commit();


                    Message = "Shift saved successfully!!";
                    success = true;
                }
                else
                {
                    return(new ReturnResult {
                        Message = "UnSuccess", Success = false
                    });
                }
            }
            else
            {
                var existingShift = _genericService.ShitfAssignment.GetById(ShitfAssignment.Id);
                if (existingShift != null)
                {
                    ShitfAssignment.FromDate = Convert.ToDateTime(ShitfAssignment.strFromDate);
                    ShitfAssignment.ToDate   = Convert.ToDateTime(ShitfAssignment.strToDate);
                    var result = _genericService.ShitfAssignment.GetAll().Where(y => y.Id != ShitfAssignment.Id && (
                                                                                    y.FromDate >= ShitfAssignment.FromDate &&
                                                                                    y.ToDate <= ShitfAssignment.ToDate ||
                                                                                    y.FromDate >= ShitfAssignment.FromDate &&
                                                                                    y.FromDate <= ShitfAssignment.ToDate ||
                                                                                    y.ToDate >= ShitfAssignment.FromDate &&
                                                                                    y.ToDate <= ShitfAssignment.ToDate ||
                                                                                    y.FromDate <= ShitfAssignment.ToDate &&
                                                                                    y.ToDate >= ShitfAssignment.FromDate) &&
                                                                                (y.UserId == ShitfAssignment.UserId) && (y.ShitfId == ShitfAssignment.ShitfId) && y.IsActive
                                                                                ).AsQueryable();

                    if (result.Count() == 0)
                    {
                        existingShift.ShitfId    = ShitfAssignment.ShitfId;
                        existingShift.UserId     = ShitfAssignment.UserId;
                        existingShift.GateId     = ShitfAssignment.GateId;
                        existingShift.BuildingId = ShitfAssignment.BuildingId;
                        existingShift.FromDate   = DateTime.Parse(ShitfAssignment.strFromDate);
                        existingShift.ToDate     = DateTime.Parse(ShitfAssignment.strToDate);
                        existingShift.FromDate   = DateTime.ParseExact(ShitfAssignment.strFromDate, "dd/MM/yyyy", System.Globalization.CultureInfo.InvariantCulture); //Convert.ToDateTime(ShitfAssignment.strFromDate);
                        existingShift.ToDate     = DateTime.ParseExact(ShitfAssignment.strToDate, "dd/MM/yyyy", System.Globalization.CultureInfo.InvariantCulture);   //Convert.ToDateTime(ShitfAssignment.strToDate);
                        existingShift.IsActive   = true;
                        _genericService.ShitfAssignment.Update(existingShift);
                        Message = "Shift update successfully!!";
                        success = true;
                        _genericService.Commit();
                    }
                    else
                    {
                        return(new ReturnResult {
                            Message = "UnSuccess", Success = false
                        });
                    }
                }
                ;
            }

            return(new ReturnResult {
                Message = Message, Success = success
            });
        }
Example #9
0
        public ActionResult Edit(tblshiftmethod tblmc)
        {
            if ((Session["UserId"] == null) || (Session["UserId"].ToString() == String.Empty))
            {
                return(RedirectToAction("Login", "Login", null));
            }
            ViewBag.Logout = Session["Username"];
            ViewBag.roleid = Session["RoleID"];
            String Username = Session["Username"].ToString();
            int    UserID   = Convert.ToInt32(Session["UserID"]);

            string shiftmethodname = tblmc.ShiftMethodName;
            int    shiftmethodId   = tblmc.ShiftMethodID;
            var    doesthisExist   = db.tblshiftmethods.Where(m => m.IsDeleted == 0 && m.ShiftMethodName == shiftmethodname && m.ShiftMethodID != shiftmethodId).ToList();

            if (doesthisExist.Count == 0)
            {
                #region Active Log Code
                //tblmachinecategory OldData = db.tblmachinecategories.Find(tblmc.ID);
                //IEnumerable<string> FullData = ActiveLog.EnumeratePropertyDifferences<tblmachinecategory>(OldData, tblmc);
                //ICollection<tblmachinecategory> c = FullData as ICollection<tblmachinecategory>;
                //int Count = c.Count;
                //if (Count != 0)
                //{
                //    string CompleteModificationdetail = null;
                //    for (int i = 0; i < Count; i++)
                //    {
                //        CompleteModificationdetail = CompleteModificationdetail + "-" + FullData.Take(i).ToArray();
                //    }
                //    Action = "Edit";
                //    ActiveLogStorage Obj = new ActiveLogStorage();
                //    Obj.SaveActiveLog(Action, Controller, Username, UserID, CompleteModificationdetail);
                //}
                #endregion //End Active Log

                //check if shift method is in use or was used and now its being modified.
                ShiftDetails sd            = new ShiftDetails();
                int          shiftmethodid = Convert.ToInt32(tblmc.ShiftMethodID);
                bool         tick          = sd.IsThisShiftMethodIsInActionOrEnded(shiftmethodid);
                if (tick)
                {
                    tblshiftmethod tsm = new tblshiftmethod();
                    tsm.CreatedBy       = UserID;
                    tsm.CreatedOn       = DateTime.Now;
                    tsm.IsDeleted       = 0;
                    tsm.NoOfShifts      = tblmc.NoOfShifts;
                    tsm.ShiftMethodDesc = tblmc.ShiftMethodDesc;
                    tsm.ShiftMethodName = tblmc.ShiftMethodName;
                    db.tblshiftmethods.Add(tsm);
                    db.SaveChanges();

                    tblmc.ModifiedBy      = UserID;
                    tblmc.ModifiedOn      = DateTime.Now;
                    db.Entry(tblmc).State = EntityState.Modified;
                    db.SaveChanges();
                    return(RedirectToAction("Index"));
                }
                else
                {
                    tblmc.ModifiedBy      = UserID;
                    tblmc.ModifiedOn      = DateTime.Now;
                    db.Entry(tblmc).State = EntityState.Modified;
                    db.SaveChanges();
                    return(RedirectToAction("Index"));
                }
            }
            else
            {
                TempData["Error"] = "Shift Method Exists.";
                return(View(tblmc));
            }
        }