Пример #1
0
        public JsonResult Save_Room(tblRoom [] room)
        {
            var value = 0;
            var Id    = 0;

            try
            {
                if (room[0].Id > 0)
                {
                    var update = db.tblRooms.Find(room[0].Id);
                    update.R_Name     = room[0].R_Name;
                    update.CategoryId = room[0].CategoryId;
                    update.R_Note     = room[0].R_Note;
                    db.SaveChanges();
                    value = room[0].Id;
                }
                else
                {
                    var roomnew = new tblRoom();
                    var layid   = (from R in db.tblRooms
                                   where R.Id > 0
                                   orderby R.Id descending
                                   select new
                    {
                        Id_room = R.Id
                    }).Take(1).ToArray();

                    if (layid.Any())
                    {
                        roomnew.Id = layid[0].Id_room + 1;
                    }
                    else
                    {
                        roomnew.Id = 1;
                    }
                    Id = roomnew.Id;

                    roomnew.R_Name     = room[0].R_Name;
                    roomnew.CategoryId = room[0].CategoryId;
                    roomnew.R_Note     = room[0].R_Note;
                    roomnew.R_Active   = true;
                    roomnew.R_Status   = 0;
                    db.tblRooms.Add(roomnew);
                    db.SaveChanges();
                    value = roomnew.Id;
                }
            }
            catch (Exception)
            {
                value = 0;
            }
            var data = new { sussecc = value, Id = Id };

            return(Json(data, JsonRequestBehavior.AllowGet));
        }
        public ActionResult Edit(ServiceRequestsModels ServiceRequest)
        {
            if (ModelState.IsValid)
            {
                var RequestId   = Convert.ToInt32(ServiceRequest.RequestType);
                var requesttype = db.tblServiceTypes.Where(x => x.Id == RequestId).FirstOrDefault()?.ServiceDescription;

                if (!string.IsNullOrEmpty(ServiceRequest.Area))
                {
                    var TblArea = new tblArea
                    {
                        FacilityId = ServiceRequest.FacilityId,
                        BuildingId = ServiceRequest.BuildingId,
                        FloorId    = ServiceRequest.FloorId,
                        AreaName   = ServiceRequest.Area
                    };
                    //TblArea.Id = db.tblAreas.Max(p => p.Id) + 1;
                    db.tblAreas.Add(TblArea);
                    db.SaveChanges();
                    ServiceRequest.AreaId = TblArea.Id;
                }

                if (!string.IsNullOrEmpty(ServiceRequest.Room))
                {
                    var TblRoom = new tblRoom
                    {
                        FacilityId = ServiceRequest.FacilityId,
                        BuildingId = ServiceRequest.BuildingId,
                        FloorId    = ServiceRequest.FloorId,
                        AreaId     = ServiceRequest.AreaId,
                        RoomName   = ServiceRequest.Room
                    };
                    //TblRoom.Id = db.tblRooms.Max(p => p.Id) + 1;
                    db.tblRooms.Add(TblRoom);
                    db.SaveChanges();
                    ServiceRequest.RoomId = TblRoom.Id;
                }

                var TblServiceRequest = db.tblServiceRequests.Where(x => x.ServiceRequestNumber == ServiceRequest.ServiceRequestNumber).FirstOrDefault();

                tblServiceRequestStatu TBLStatus = new tblServiceRequestStatu();
                TBLStatus.dtTimeStamp       = DateTime.Now;
                TBLStatus.iServiceRequestId = ServiceRequest.Id;
                TBLStatus.iStatusId         = db.TblServiceStates.Where(x => x.ServiceState == "Open").FirstOrDefault().id;
                db.tblServiceRequestStatus.Add(TBLStatus);

                TblServiceRequest.OccupantName       = ServiceRequest.OccupantName;
                TblServiceRequest.ContactName        = ServiceRequest.ContactName;
                TblServiceRequest.ContactNumber      = ServiceRequest.ContactNumber;
                TblServiceRequest.ContactEmail       = ServiceRequest.ContactEmail;
                TblServiceRequest.FacilityId         = ServiceRequest.FacilityId;
                TblServiceRequest.BuildingId         = ServiceRequest.BuildingId;
                TblServiceRequest.FloorId            = ServiceRequest.FloorId;
                TblServiceRequest.AreaId             = ServiceRequest.AreaId;
                TblServiceRequest.RoomId             = ServiceRequest.RoomId;
                TblServiceRequest.RequestType        = Convert.ToString(ServiceRequest.RequestType);
                TblServiceRequest.CategoryIdParentId = Convert.ToInt32(db.tblServiceTypes.Where(x => x.Id == ServiceRequest.RequestType).FirstOrDefault()?.ServiceType);
                TblServiceRequest.AssetGroupId       = ServiceRequest.AssetGroupId;
                TblServiceRequest.CategoryId         = ServiceRequest.CategoryId;
                TblServiceRequest.AssetTypeId        = ServiceRequest.CategoryId;
                TblServiceRequest.RequestDescription = ServiceRequest.RequestDescription;
                TblServiceRequest.ISeniorTechId      = ServiceRequest.ISeniorTechId ?? TblServiceRequest.ISeniorTechId;
                TblServiceRequest.Severity           = ServiceRequest.Severity ?? (TblServiceRequest.Severity ?? 3);

                db.SaveChanges();

                List <int> ResourcesList = new List <int>();
                var        WorkOrder     = db.tblWorkOrders.Where(x => x.ServiceRequestId == TblServiceRequest.Id).FirstOrDefault();

                WorkOrder.CategoryTypeId     = ServiceRequest.CategoryId;
                WorkOrder.CategoryIdParentId = Convert.ToInt32(db.tblServiceTypes.Where(x => x.Id == ServiceRequest.RequestType).FirstOrDefault()?.ServiceType);

                var ExistingResources = db.tblWorkOrderResources.Where(x => x.WorkOrderId == WorkOrder.Id).Select(y => y.WorkforceId)?.ToList();

                //Adding moddified reosurces in tblWorkOrderResource
                if (ServiceRequest.ResourceID != null)
                {
                    var NewResources = ServiceRequest.ResourceID.ToList();

                    if (NewResources.Any())
                    {
                        foreach (var resource in NewResources)
                        {
                            if (!ExistingResources.Contains(resource))
                            {
                                var Tblworkorderresources = new tblWorkOrderResource
                                {
                                    WorkforceId = resource,
                                    WorkOrderId = WorkOrder.Id
                                };

                                var TblServiceRequestResources = new tblServiceRequestResource
                                {
                                    ServiceRequestId = TblServiceRequest.Id,
                                    workforceId      = resource
                                };

                                ResourcesList.Add(resource);
                                db.tblServiceRequestResources.Add(TblServiceRequestResources);

                                db.tblWorkOrderResources.Add(Tblworkorderresources);
                            }
                        }

                        foreach (var resource in ExistingResources)
                        {
                            if (!NewResources.Contains(Convert.ToInt32(resource)))
                            {
                                var Tblworkorderresources = db.tblWorkOrderResources.Where(x => x.WorkforceId == resource && x.WorkOrderId == WorkOrder.Id).FirstOrDefault();

                                var TblServiceRequestResources = db.tblServiceRequestResources.Where(x => x.workforceId == resource && x.ServiceRequestId == TblServiceRequest.Id).FirstOrDefault();

                                db.tblWorkOrderResources.Remove(Tblworkorderresources);
                                db.tblServiceRequestResources.Remove(TblServiceRequestResources);
                            }
                        }
                        db.SaveChanges();
                    }
                }

                foreach (var resource in ResourcesList)
                {
                    if (resource != 0)
                    {
                        tblNotificationQueue notification = new tblNotificationQueue();
                        notification.ContactNumber = db.tblWorkForces.Where(x => x.Id == resource).FirstOrDefault().ContactNumber;
                        notification.MessageBody   = WorkOrder.WorkOrderRefNo + " " +
                                                     ServiceRequest.RequestDescription + " " + ServiceRequest.ContactName + " " +
                                                     ServiceRequest.ContactNumber + Convert.ToString(ServiceRequest.Severity ?? 3) + " " +
                                                     db.tblBuildings.Where(x => x.Id == ServiceRequest.BuildingId).FirstOrDefault()?.BuildingName + "/" +
                                                     db.tblFloors.Where(x => x.Id == ServiceRequest.FloorId).FirstOrDefault()?.FloorName + "/" +
                                                     db.tblAreas.Where(x => x.Id == ServiceRequest.AreaId).FirstOrDefault()?.AreaName + "/" +
                                                     db.tblRooms.Where(x => x.Id == ServiceRequest.RoomId).FirstOrDefault()?.RoomName;

                        notification.IsSMSSent       = false;
                        notification.SMSSentDateTime = null;
                        notification.FormRequestType = "WorkOrderUpdate";
                        notification.QueuedDate      = DateTime.Now;

                        db.tblNotificationQueues.Add(notification);
                    }
                }
                db.SaveChanges();

                //Adding files to table
                if (ServiceRequest.Files != null && ServiceRequest.Files.Any())
                {
                    foreach (var file in ServiceRequest.Files)
                    {
                        if (file != null && file.ContentLength > 0)
                        {
                            string newfilename = Path.GetFileNameWithoutExtension(file.FileName) + "_" + Guid.NewGuid() + "SREQ" + Path.GetExtension(file.FileName);
                            string path        = Path.Combine("C:\\Program Files (x86)\\Johnson Controls\\EFIRM\\ImagesHelpDesk\\ServiceRequest",
                                                              newfilename);
                            file.SaveAs(path);

                            var TblServiceRequestImages = new tblServiceRequestImage
                            {
                                sImageName        = newfilename,
                                nServiceRequestId = TblServiceRequest.Id
                            };

                            db.tblServiceRequestImages.Add(TblServiceRequestImages);
                        }
                    }
                    db.SaveChanges();
                }

                return(RedirectToAction("Index"));
            }
            ViewBag.Occupants     = new SelectList(db.tblOccupants, "Id", "OccupantName");
            ViewBag.Facilities    = new SelectList(db.tblFacilities, "Id", "FacilityName");
            ViewBag.Groups        = new SelectList(db.tblAssetGroups, "Id", "AssetGroup");
            ViewBag.RequestTypes  = new SelectList(db.tblServiceTypes, "Id", "ServiceDescription");
            ViewBag.Severities    = new SelectList(db.tblSeverities, "Id", "SeverityLevel");
            ViewBag.LeadResources = new SelectList(db.tblWorkForces, "Id", "PersonName");
            return(View(ServiceRequest));
        }
        public ActionResult Create(ServiceRequestsModels ServiceRequest)
        {
            if (ModelState.IsValid)
            {
                var RequestId   = Convert.ToInt32(ServiceRequest.RequestType);
                var requesttype = db.tblServiceTypes.Where(x => x.Id == RequestId).FirstOrDefault()?.ServiceDescription;

                if (!string.IsNullOrEmpty(ServiceRequest.Area))
                {
                    var TblArea = new tblArea
                    {
                        FacilityId = ServiceRequest.FacilityId,
                        BuildingId = ServiceRequest.BuildingId,
                        FloorId    = ServiceRequest.FloorId,
                        AreaName   = ServiceRequest.Area
                    };
                    //TblArea.Id = db.tblAreas.Max(p => p.Id) + 1;
                    db.tblAreas.Add(TblArea);
                    db.SaveChanges();
                    ServiceRequest.AreaId = TblArea.Id;
                }

                if (!string.IsNullOrEmpty(ServiceRequest.Room))
                {
                    var TblRoom = new tblRoom
                    {
                        FacilityId = ServiceRequest.FacilityId,
                        BuildingId = ServiceRequest.BuildingId,
                        FloorId    = ServiceRequest.FloorId,
                        AreaId     = ServiceRequest.AreaId,
                        RoomName   = ServiceRequest.Room
                    };
                    //TblRoom.Id = db.tblRooms.Max(p => p.Id) + 1;
                    db.tblRooms.Add(TblRoom);
                    db.SaveChanges();
                    ServiceRequest.RoomId = TblRoom.Id;
                }

                var TblServiceRequest = new tblServiceRequest
                {
                    OccupantName       = ServiceRequest.OccupantName,
                    ContactName        = ServiceRequest.ContactName,
                    ContactNumber      = ServiceRequest.ContactNumber,
                    ContactEmail       = ServiceRequest.ContactEmail,
                    FacilityId         = ServiceRequest.FacilityId,
                    BuildingId         = ServiceRequest.BuildingId,
                    FloorId            = ServiceRequest.FloorId,
                    AreaId             = ServiceRequest.AreaId,
                    RoomId             = ServiceRequest.RoomId,
                    RequestType        = Convert.ToString(ServiceRequest.RequestType),
                    AssetGroupId       = ServiceRequest.AssetGroupId,
                    CategoryId         = ServiceRequest.CategoryId,
                    AssetTypeId        = ServiceRequest.CategoryId,
                    RequestDescription = ServiceRequest.RequestDescription,
                    ISeniorTechId      = ServiceRequest.ISeniorTechId,
                    Severity           = ServiceRequest.Severity ?? 3,
                    WhoLogged          = System.Web.HttpContext.Current.User.Identity.Name,
                    Status             = "Open",
                    RequestDate        = System.DateTime.Now,
                    IsThroughService   = false,
                    CategoryIdParentId = Convert.ToInt32(db.tblServiceTypes.Where(x => x.Id == ServiceRequest.RequestType).FirstOrDefault()?.ServiceType)
                };
                string   ServiceRequestNumber         = string.Empty;
                var      LastServiceRequestNumber     = (db.tblServiceRequests.Where(y => y.ServiceRequestNumber.Contains(requesttype)).OrderByDescending(x => x.Id).FirstOrDefault()?.ServiceRequestNumber).Split('/');;
                DateTime LastServiceRequestNumberDate = DateTime.ParseExact(LastServiceRequestNumber[2], "yyMMdd", CultureInfo.InvariantCulture);

                if (LastServiceRequestNumberDate.Year == DateTime.Today.Year &&
                    LastServiceRequestNumberDate.Month == DateTime.Today.Month)
                {
                    ServiceRequestNumber = "SR/" + requesttype + "/" +
                                           DateTime.Today.ToString("yy") + DateTime.Now.Month.ToString("d2") +
                                           DateTime.Now.Day.ToString("d2")
                                           + "/" + (Convert.ToInt32(LastServiceRequestNumber[3]) + 1);
                }
                else
                {
                    ServiceRequestNumber = "SR/" + requesttype + "/" +
                                           DateTime.Today.ToString("yy") + DateTime.Now.Month.ToString("d2") +
                                           DateTime.Now.Day.ToString("d2")
                                           + "/" + 1;
                }
                TblServiceRequest.ServiceRequestNumber = ServiceRequestNumber;
                db.tblServiceRequests.Add(TblServiceRequest);
                db.SaveChanges();


                string   WorkOrderRefNumber         = string.Empty;
                var      LastWorkOrderRefNumber     = (db.tblWorkOrders.Where(y => y.WorkOrderRefNo.Contains(requesttype)).OrderByDescending(x => x.Id).FirstOrDefault()?.WorkOrderRefNo).Split('/');;
                DateTime LastWorkOrderRefNumberDate = DateTime.ParseExact(LastWorkOrderRefNumber[2], "yyMMdd", CultureInfo.InvariantCulture);
                var      WorkOrderId = Convert.ToInt32(ServiceRequest.RequestType);

                if (LastWorkOrderRefNumberDate.Year == DateTime.Today.Year &&
                    LastWorkOrderRefNumberDate.Month == DateTime.Today.Month)
                {
                    WorkOrderRefNumber = "WO/" + requesttype + "/" +
                                         DateTime.Today.ToString("yy") + DateTime.Now.Month.ToString("d2") +
                                         DateTime.Now.Day.ToString("d2")
                                         + "/" + (Convert.ToInt32(LastWorkOrderRefNumber[3]) + 1);
                }
                else
                {
                    WorkOrderRefNumber = "WO/" + requesttype + "/" +
                                         DateTime.Today.ToString("yy") + DateTime.Now.Month.ToString("d2") +
                                         DateTime.Now.Day.ToString("d2")
                                         + "/" + 1;
                }

                var TblWorkOrders = new tblWorkOrder
                {
                    WorkOrderRefNo     = WorkOrderRefNumber,
                    ServiceRequestId   = TblServiceRequest.Id,
                    WorkOrderDate      = DateTime.Now,
                    Status             = "Open",
                    RequesterId        = Convert.ToInt32(Session["UserID"]),
                    CategoryTypeId     = ServiceRequest.CategoryId,
                    IsThroughService   = false,
                    CategoryIdParentId = Convert.ToInt32(db.tblServiceTypes.Where(x => x.Id == ServiceRequest.RequestType).FirstOrDefault()?.ServiceType)
                };
                db.tblWorkOrders.Add(TblWorkOrders);
                db.SaveChanges();

                var        NewServiceRequest = tblServiceRequest.Where(x => x.ServiceRequestNumber == ServiceRequestNumber)?.FirstOrDefault();
                List <int> ResourcesList     = new List <int>();
                //Adding reosurces in tblWorkOrderResource
                if (ServiceRequest.ResourceID != null && ServiceRequest.ResourceID.Any())
                {
                    foreach (var resource in ServiceRequest.ResourceID)
                    {
                        ResourcesList.Add(resource);
                        var Tblworkorderresources = new tblWorkOrderResource
                        {
                            WorkforceId = resource,
                            WorkOrderId = TblWorkOrders.Id
                        };

                        var TblServiceRequestResources = new tblServiceRequestResource
                        {
                            ServiceRequestId = NewServiceRequest.Id,
                            workforceId      = resource
                        };

                        db.tblWorkOrderResources.Add(Tblworkorderresources);
                        db.tblServiceRequestResources.Add(TblServiceRequestResources);
                    }
                    db.SaveChanges();
                }
                else
                {
                    //Service Request is not created from Admin mode so we need to so auto assign of resource
                    var TblShifts         = db.tblShifts?.ToArray();
                    var TblShiftRostering = db.tblShiftRosterings;
                    var TblShiftException = db.tblShiftExceptions;
                    var TimeNow           = TimeSpan.Parse(DateTime.Now.ToString("HH:mm"));

                    var ShiftNow = (TimeNow.Hours > 17 || TimeNow.Hours < 7) ? TblShifts[1] : TblShifts[0];



                    var ResouceonLeaveInCurrentShiftToday = TblShiftException.Where(x => x.ShiftId == ShiftNow.Id && x.FromDate <= DateTime.Now && x.ToDate >= DateTime.Now).Select(x => x.WorkForceId);

                    foreach (var resource in ResouceonLeaveInCurrentShiftToday)
                    {
                        var res = db.tblShiftRosterings.FirstOrDefault(x => x.WorkForceId == resource);
                        TblShiftRostering.Remove(res);
                    }

                    var dummy = TblShifts.ToList();
                    var LeastUsedResourceInCurrentShift = TblShiftRostering.Where(x => x.ShiftId == ShiftNow.Id).OrderBy(x => x.LastUsedDateTime).FirstOrDefault();

                    ResourcesList.Add(Convert.ToInt32(LeastUsedResourceInCurrentShift?.WorkForceId));

                    var Tblworkorderresources = new tblWorkOrderResource
                    {
                        WorkforceId = LeastUsedResourceInCurrentShift?.WorkForceId,
                        WorkOrderId = TblWorkOrders.Id
                    };
                    var TblServiceRequestResources = new tblServiceRequestResource
                    {
                        ServiceRequestId = NewServiceRequest.Id,
                        workforceId      = LeastUsedResourceInCurrentShift?.WorkForceId,
                    };

                    db.tblServiceRequestResources.Add(TblServiceRequestResources);

                    db.tblWorkOrderResources.Add(Tblworkorderresources);
                    NewServiceRequest.ISeniorTechId = LeastUsedResourceInCurrentShift?.WorkForceId;

                    LeastUsedResourceInCurrentShift.LastUsedDateTime = DateTime.Now;

                    db.SaveChanges();
                }

                foreach (var resource in ResourcesList)
                {
                    if (resource != 0)
                    {
                        tblNotificationQueue notification = new tblNotificationQueue();
                        notification.ContactNumber = db.tblWorkForces.Where(x => x.Id == resource).FirstOrDefault().ContactNumber;
                        notification.MessageBody   = TblWorkOrders.WorkOrderRefNo + " " +
                                                     ServiceRequest.RequestDescription + " " + ServiceRequest.ContactName + " " +
                                                     ServiceRequest.ContactNumber + Convert.ToString(ServiceRequest.Severity ?? 3) + " " +
                                                     db.tblBuildings.Where(x => x.Id == ServiceRequest.BuildingId).FirstOrDefault()?.BuildingName + "/" +
                                                     db.tblFloors.Where(x => x.Id == ServiceRequest.FloorId).FirstOrDefault()?.FloorName + "/" +
                                                     db.tblAreas.Where(x => x.Id == ServiceRequest.AreaId).FirstOrDefault()?.AreaName + "/" +
                                                     db.tblRooms.Where(x => x.Id == ServiceRequest.RoomId).FirstOrDefault()?.RoomName;

                        notification.IsSMSSent       = false;
                        notification.SMSSentDateTime = null;
                        notification.QueuedDate      = DateTime.Now;
                        notification.FormRequestType = "WorkOrderAdd";

                        db.tblNotificationQueues.Add(notification);
                    }
                }
                db.SaveChanges();

                //Adding files to table
                if (ServiceRequest.Files != null && ServiceRequest.Files.Any())
                {
                    foreach (var file in ServiceRequest.Files)
                    {
                        if (file != null && file.ContentLength > 0)
                        {
                            string newfilename = Path.GetFileNameWithoutExtension(file.FileName) + "_" + Guid.NewGuid() + "SREQ" + Path.GetExtension(file.FileName);
                            string path        = Path.Combine("C:\\Program Files (x86)\\Johnson Controls\\EFIRM\\ImagesHelpDesk\\ServiceRequest",
                                                              newfilename);
                            file.SaveAs(path);

                            var TblServiceRequestImages = new tblServiceRequestImage
                            {
                                sImageName        = newfilename,
                                nServiceRequestId = TblServiceRequest.Id
                            };
                            db.tblServiceRequestImages.Add(TblServiceRequestImages);
                        }
                    }
                    db.SaveChanges();
                }

                tblServiceRequestStatu TBLStatus = new tblServiceRequestStatu();
                TBLStatus.dtTimeStamp       = DateTime.Now;
                TBLStatus.iServiceRequestId = NewServiceRequest.Id;
                TBLStatus.iStatusId         = db.TblServiceStates.Where(x => x.ServiceState == "Open").FirstOrDefault().id;
                db.tblServiceRequestStatus.Add(TBLStatus);

                return(RedirectToAction("Index", new { ServiceRequestCreated = true }));
            }
            ViewBag.Occupants     = new SelectList(db.tblOccupants, "Id", "OccupantName");
            ViewBag.Facilities    = new SelectList(db.tblFacilities, "Id", "FacilityName");
            ViewBag.Groups        = new SelectList(db.tblAssetGroups, "Id", "AssetGroup");
            ViewBag.RequestTypes  = new SelectList(db.tblServiceTypes, "Id", "ServiceDescription");
            ViewBag.Severities    = new SelectList(db.tblSeverities, "Id", "SeverityLevel");
            ViewBag.LeadResources = new SelectList(db.tblWorkForces, "Id", "PersonName");
            return(View(ServiceRequest));
        }
Пример #4
0
        void RedrawRoom(tblRoom Room)
        {
            CinemaDataContext Context = new CinemaDataContext();

            tbRoomID.Text = Room.RoomID.ToString();

            wrapPanel1.Children.Clear();
            double SeatWidth  = wrapPanel1.ActualWidth / (Room.SeatsNumber + 1);
            double SeatHeight = wrapPanel1.ActualHeight / (Room.RowNumber + 1);

            Seats = new Seat[Room.RowNumber, Room.SeatsNumber];

            TextBlock TB = new TextBlock();

            TB.Text   = "";
            TB.Width  = SeatWidth;
            TB.Height = SeatHeight;
            TB.HorizontalAlignment = System.Windows.HorizontalAlignment.Center;
            TB.VerticalAlignment   = System.Windows.VerticalAlignment.Center;
            TB.Background          = new SolidColorBrush(Colors.AntiqueWhite);
            wrapPanel1.Children.Add(TB);
            for (int j = 0; j < Room.SeatsNumber; j++)
            {
                TB        = new TextBlock();
                TB.Text   = (j + 1).ToString();
                TB.Width  = SeatWidth;
                TB.Height = SeatHeight;
                TB.HorizontalAlignment = System.Windows.HorizontalAlignment.Center;
                TB.VerticalAlignment   = System.Windows.VerticalAlignment.Center;
                TB.Background          = new SolidColorBrush(Colors.AntiqueWhite);
                wrapPanel1.Children.Add(TB);
            }
            for (int i = 0; i < Room.RowNumber; i++)
            {
                TB        = new TextBlock();
                TB.Text   = (i + 1).ToString();
                TB.Width  = SeatWidth;
                TB.Height = SeatHeight;
                TB.HorizontalAlignment = System.Windows.HorizontalAlignment.Center;
                TB.VerticalAlignment   = System.Windows.VerticalAlignment.Center;
                TB.Background          = new SolidColorBrush(Colors.AntiqueWhite);
                wrapPanel1.Children.Add(TB);

                for (int j = 0; j < Room.SeatsNumber; j++)
                {
                    Button          B     = new Button();
                    SolidColorBrush Brush = new SolidColorBrush();

                    int Vip = (from S in Context.tblSeats
                               where S.RoomID == Room.RoomID &&
                               S.Row == i + 1 && S.Seat == j + 1
                               select S.Vip).ToArray()[0];
                    if (Vip == 0)
                    {
                        Brush             = (SolidColorBrush)borderVIP.Background;
                        Seats[i, j].IsVip = true;
                    }
                    else
                    {
                        Brush             = (SolidColorBrush)borderFree.Background;
                        Seats[i, j].IsVip = false;
                    }


                    if ((from T in Context.tblTickets
                         where T.ShowID == Show.ShowID && T.Row == i + 1 && T.Seat == j + 1 && T.Status == 1
                         select T).Count() != 0)
                    {
                        Brush = (SolidColorBrush)borderBusy.Background;
                        Seats[i, j].IsFree = false;
                    }
                    else
                    {
                        Seats[i, j].IsFree = true;
                    }

                    Seats[i, j].IsSelected = false;

                    B.Tag                 = i.ToString() + " " + j.ToString();
                    B.Background          = Brush;
                    B.Width               = SeatWidth;
                    B.Height              = SeatHeight;
                    B.HorizontalAlignment = System.Windows.HorizontalAlignment.Stretch;
                    B.VerticalAlignment   = System.Windows.VerticalAlignment.Stretch;
                    B.Click              += btnSeat_Click;

                    wrapPanel1.Children.Add(B);
                }
            }
        }
Пример #5
0
 public ActionResult AddOrEdit(HostelViewModel hm)
 {
     if (ModelState.IsValid)
     {
         if (hm.HostelId == 0)
         {
             HttpPostedFileBase fup   = Request.Files["Photo"];
             HttpPostedFileBase one   = Request.Files["Photo1"];
             HttpPostedFileBase two   = Request.Files["Photo2"];
             HttpPostedFileBase three = Request.Files["Photo3"];
             //Adding New One
             tblHostel th    = new tblHostel();
             tblPhoto  photo = new tblPhoto();
             th.HostelName      = hm.HostelName;
             th.Description     = hm.Description;
             th.Address         = hm.Address;
             th.Phone           = hm.Phone;
             th.Star            = hm.Star;
             th.Capacity        = hm.Capacity;
             th.DescriptionNext = hm.DescriptionNext;
             th.Facilites       = hm.Facilites;
             th.Photo           = fup.FileName;
             fup.SaveAs(Path.Combine(Server.MapPath("~/Images/Hostel/"), fup.FileName));
             th.Email       = hm.Email;
             th.MapLocation = hm.MapLocation;
             foreach (var item in db.tblWardens.ToList())
             {
                 if (User.Identity.Name == item.UserName)
                 {
                     th.WardenId = item.WardenId;
                 }
             }
             db.tblHostels.Add(th);
             db.SaveChanges();
             tblRoom  to1  = new tblRoom();
             tblRoom  to2  = new tblRoom();
             tblRoom  to3  = new tblRoom();
             tblPrice pto1 = new tblPrice();
             tblPrice pto2 = new tblPrice();
             tblPrice pto3 = new tblPrice();
             photo.Photo = one.FileName;
             one.SaveAs(Path.Combine(Server.MapPath("~/Images/Hostel/"), one.FileName));
             photo.HostelId = th.HostelId;
             to1.RoomName   = "One Sitter";
             to1.HostelId   = th.HostelId;
             pto1.Price     = hm.OnesitterPrice;
             db.tblPhotoes.Add(photo);
             db.tblPrices.Add(pto1);
             db.SaveChanges();
             to1.PriceId = pto1.PriceId;
             db.tblRooms.Add(to1);
             db.SaveChanges();
             photo.Photo = two.FileName;
             two.SaveAs(Path.Combine(Server.MapPath("~/Images/Hostel/"), two.FileName));
             photo.HostelId = th.HostelId;
             to2.RoomName   = "Two Sitter";
             to2.HostelId   = th.HostelId;
             pto2.Price     = hm.TwositterPrice;
             db.tblPhotoes.Add(photo);
             db.tblPrices.Add(pto2);
             db.SaveChanges();
             to2.PriceId = pto2.PriceId;
             db.tblRooms.Add(to2);
             db.SaveChanges();
             photo.Photo = three.FileName;
             three.SaveAs(Path.Combine(Server.MapPath("~/Images/Hostel/"), three.FileName));
             photo.HostelId = th.HostelId;
             to3.RoomName   = "Three Sitter";
             to3.HostelId   = th.HostelId;
             pto3.Price     = hm.ThreesitterPrice;
             db.tblPhotoes.Add(photo);
             db.tblPrices.Add(pto3);
             db.SaveChanges();
             to3.PriceId = pto3.PriceId;
             db.tblRooms.Add(to3);
             db.SaveChanges();
         }
         else
         {
             HttpPostedFileBase fup   = Request.Files["Photo"];
             HttpPostedFileBase one   = Request.Files["Photo1"];
             HttpPostedFileBase two   = Request.Files["Photo2"];
             HttpPostedFileBase three = Request.Files["Photo3"];
             tblHostel          th    = db.tblHostels.Where(x => x.HostelId == hm.HostelId).FirstOrDefault();
             th.HostelName  = hm.HostelName;
             th.Description = hm.Description;
             th.Address     = hm.Address;
             th.Phone       = hm.Phone;
             th.Star        = hm.Star;
             th.Capacity    = hm.Capacity;
             th.Email       = hm.DescriptionNext;
             th.Facilites   = hm.Facilites;
             th.Email       = hm.Email;
             th.MapLocation = hm.MapLocation;
             int i = 0;
             foreach (var item in db.tblPhotoes.ToList())
             {
                 if (item.HostelId == hm.HostelId && i == 0)
                 {
                     if (one.ContentLength > 0)
                     {
                         System.IO.File.Delete(Path.Combine(Server.MapPath("~/Images/Hostel/"), item.Photo));
                         item.Photo = one.FileName;
                         one.SaveAs(Path.Combine(Server.MapPath("~/Images/Hostel/"), one.FileName));
                         break;
                     }
                     if (two.ContentLength > 0)
                     {
                         System.IO.File.Delete(Path.Combine(Server.MapPath("~/Images/Hostel/"), item.Photo));
                         one.SaveAs(Path.Combine(Server.MapPath("~/Images/Hostel/"), two.FileName));
                         item.Photo = two.FileName;
                         break;
                     }
                     if (three.ContentLength > 0)
                     {
                         System.IO.File.Delete(Path.Combine(Server.MapPath("~/Images/Hostel/"), item.Photo));
                         one.SaveAs(Path.Combine(Server.MapPath("~/Images/Hostel/"), three.FileName));
                         item.Photo = three.FileName;
                         break;
                     }
                 }
             }
             db.SaveChanges();
             List <tblRoom> to = db.tblRooms.Where(x => x.HostelId == hm.HostelId).ToList();
             foreach (var item in to)
             {
                 if (item.RoomName == "One Sitter")
                 {
                     item.tblPrice.Price = hm.OnesitterPrice;
                 }
                 if (item.RoomName == "Two Sitter")
                 {
                     item.tblPrice.Price = hm.TwositterPrice;
                 }
                 if (item.RoomName == "Three Sitter")
                 {
                     item.tblPrice.Price = hm.ThreesitterPrice;
                 }
             }
             db.SaveChanges();
         }
     }
     return(RedirectToAction("Index", "Opening"));
 }