示例#1
0
        public ActionResult Edit(int id, HotelInfos model, FormCollection frmColl)
        {
            if (!ModelState.IsValid)
            {
                return(View());
            }
            else
            {
                bool Status = model.StatusId == 0 ? true : false;

                string strHotelRoomTypeList = string.Empty, strHotelFacityList = string.Empty, strHotelCityInfoList = string.Empty, strHotelAdditionalChargeList = string.Empty;
                string sfileName = string.Empty;

                var httpFileCollection = Request.Files;
                for (int i = 0; i < httpFileCollection.Count; i++)
                {
                    var httpPostedFile = httpFileCollection[i];
                    if (httpPostedFile.ContentLength > 0)
                    {
                        string FileExtension = Path.GetExtension(httpPostedFile.FileName);
                        int    FileSize      = httpPostedFile.ContentLength;

                        if (FileSize <= ATLTravelPortal.Helpers.ApplicationSettings.GetMaxPhotoSizeToUpload())
                        {
                            switch (httpPostedFile.ContentType)
                            {
                            case "image/pjpeg":
                            case "image/jpeg":
                            case "image/gif":
                            case "image/png":
                                sfileName = Guid.NewGuid().ToString() + FileExtension;
                                string sFilePath = Server.MapPath("/HotelUploads/Logo/");

                                if (!Directory.Exists(Server.MapPath("~/HotelUploads/")))
                                {
                                    Directory.CreateDirectory(Server.MapPath("~/HotelUploads/"));
                                }
                                if (!Directory.Exists(Server.MapPath("~/HotelUploads/Logo/")))
                                {
                                    Directory.CreateDirectory(Server.MapPath("~/HotelUploads/Logo/"));
                                }

                                string location = sFilePath + "/" + sfileName;
                                httpPostedFile.SaveAs(location);
                                break;

                            default:
                                return(Content("Invalid Image Type"));
                            }
                        }
                    }
                }

                foreach (string item in frmColl)
                {
                    if (item.Contains("chkbox"))
                    {
                        if (item.Contains("roomtype"))
                        {
                            string[] arrayCheckBox = item.Split('_');

                            if (strHotelRoomTypeList == "")
                            {
                                strHotelRoomTypeList = arrayCheckBox[1].ToString();
                            }
                            else
                            {
                                strHotelRoomTypeList = strHotelRoomTypeList + "," + arrayCheckBox[1].ToString();
                            }
                        }
                        else if (item.Contains("facility"))
                        {
                            string[] arrayCheckBox = item.Split('_');
                            if (strHotelFacityList == "")
                            {
                                strHotelFacityList = arrayCheckBox[1].ToString();
                            }
                            else
                            {
                                strHotelFacityList = strHotelFacityList + "," + arrayCheckBox[1].ToString();
                            }
                        }
                        else if (item.Contains("city"))
                        {
                            string[] arrayCheckBox = item.Split('_');
                            if (strHotelCityInfoList == "")
                            {
                                strHotelCityInfoList = arrayCheckBox[1].ToString();
                            }
                            else
                            {
                                strHotelCityInfoList = strHotelCityInfoList + "," + arrayCheckBox[1].ToString();
                            }
                        }
                        else if (item.Contains("additionalcharge"))
                        {
                            string[] arrayCheckBox = item.Split('_');
                            if (strHotelAdditionalChargeList == "")
                            {
                                strHotelAdditionalChargeList = arrayCheckBox[1].ToString();
                            }
                            else
                            {
                                strHotelAdditionalChargeList = strHotelAdditionalChargeList + "," + arrayCheckBox[1].ToString();
                            }
                        }
                    }
                }



                Htl_HotelInfos obj = new Htl_HotelInfos();
                var            ts  = (TravelSession)Session["TravelSessionInfo"];
                obj.HotelId   = id;
                obj.HotelName = model.HotelInfo.HotelName;
                obj.CountryId = model.HotelInfo.CountryId;
                //obj.CountryList = model.HotelCountryList;
                obj.HotelCode     = model.HotelInfo.HotelCode;
                obj.OptionalEmail = model.HotelInfo.OptionalEmail;
                obj.Address       = model.HotelInfo.Address;
                obj.Web           = model.HotelInfo.Web;
                obj.Phone         = model.HotelInfo.Phone;
                obj.Email         = model.HotelInfo.Email;
                obj.Details       = model.HotelInfo.Details;
                obj.OptionalPhone = model.HotelInfo.OptionalPhone;
                obj.isActive      = model.HotelInfo.isActive;
                obj.isDeleted     = false;
                obj.Logo          = model.HotelInfo.Logo;
                //obj.UpdatedBy  = ts.AppUserId;
                obj.UpdatedDate = DateTime.Now;

                long Hotelid = _HotelInfoRepo.HotelInfoEdit(obj);

                Htl_HotelContactInfos objs = new Htl_HotelContactInfos();
                objs.HotelId              = Hotelid;
                obj.CountryId             = model.HotelInfo.CountryId;
                objs.OwnerFullName        = model.HotelContactInfo.OwnerFullName;
                objs.OwnerDesignationId   = model.HotelContactInfo.OwnerDesignationId;
                objs.OwnerEmail           = model.HotelContactInfo.OwnerEmail;
                objs.OwnerMobile          = model.HotelContactInfo.OwnerMobile;
                objs.OwnerLandline        = model.HotelContactInfo.OwnerLandline;
                objs.OwnerTempAddress     = model.HotelContactInfo.OwnerTempAddress;
                objs.OwnerPermAddress     = model.HotelContactInfo.OwnerPermAddress;
                objs.OwnerDOB             = model.HotelContactInfo.OwnerDOB;
                objs.ContactFullName      = model.HotelContactInfo.ContactFullName;
                objs.ContactEmail         = model.HotelContactInfo.ContactEmail;
                objs.ContactMobile        = model.HotelContactInfo.ContactMobile;
                objs.ContactLandline      = model.HotelContactInfo.ContactLandline;
                objs.ContactTempAddress   = model.HotelContactInfo.ContactTempAddress;
                objs.ContactPermAddress   = model.HotelContactInfo.ContactPermAddress;
                objs.ContactDOB           = model.HotelContactInfo.ContactDOB;
                objs.ContactDesignationId = model.HotelContactInfo.ContactDesignationId;
                objs.isDeleted            = false;
                //obj.UpdatedBy = ts.AppUserId;
                obj.UpdatedDate = DateTime.Now;
                _HotelInfoRepo.HotelContactInfoEdit(objs);



                HotelCityInfoAssociation p = new HotelCityInfoAssociation();
                p.HotelId = Hotelid;
                _HotelInfoRepo.DeleteCityList(id);
                HotelInfos recordToEdit;
                recordToEdit = _HotelInfoRepo.HotelInfoById(id);
                string[] str = strHotelCityInfoList.Split(',');
                foreach (string strs in str)
                {
                    if (string.IsNullOrEmpty(strs))


                    {
                        var viewModel = new HotelInfos
                        {
                            HotelRoomTypeList            = _RoomTypeRepo.HotelRoomTypeList(),
                            HotelRoomTypeAssociationList = _HotelInfoRepo.HotelRoomTypeList(id),
                            HotelFacityList = _FacilityRepo.HotelFacilityList(),
                            HotelFacilityAssociationList = _HotelInfoRepo.HotelFacilityList(id),
                            HotelInfo                            = _HotelInfoRepo.HotelInfoLists(id),
                            HotelContactInfo                     = _ContactRepo.HotelContactInfoHotelId(id),
                            HotelCityInfo                        = _HotelInfoRepo.HotelCityList(id),
                            HotelCityInfoList                    = _CityInfoRepo.HotelCityInfoList(),
                            CountryList                          = _HotelInfoRepo.GetCountryList(),
                            HotelAdditionalChargeList            = _AdditionalChargeRepo.HotelAdditionalChargeList(),
                            HotelAdditionalChargeAssociationList = _HotelInfoRepo.HotelAdditionalChargeList(id),
                            DesignationList                      = _DesignationRepo.HotelDesignationList(),
                            CountryId                            = model.HotelInfo.CountryId,
                            // HotelTypeList = _HotelInfoRepo.GetHotelTypeList(),
                        };
                        //return RedirectToAction ("Edit", viewModel);
                    }

                    else
                    {
                        p.HotelId = Hotelid;
                        p.CityId  = Convert.ToInt32(strs);

                        _HotelInfoRepo.HotelCityInfoAssociationEdit(p);
                    }
                }



                Htl_HotelAdditionalChargeAssociation q = new Htl_HotelAdditionalChargeAssociation();
                p.HotelId = Hotelid;
                _HotelInfoRepo.DeleteAdditionalCharge(id);
                HotelInfos recordTobeEdit;
                recordTobeEdit = _HotelInfoRepo.HotelInfoById(id);
                string[] strg = strHotelAdditionalChargeList.Split(',');
                foreach (string strs in strg)
                {
                    if (string.IsNullOrEmpty(strs))
                    {
                        var viewModel = new HotelInfos
                        {
                            HotelRoomTypeList            = _RoomTypeRepo.HotelRoomTypeList(),
                            HotelRoomTypeAssociationList = _HotelInfoRepo.HotelRoomTypeList(id),
                            HotelFacityList = _FacilityRepo.HotelFacilityList(),
                            HotelFacilityAssociationList = _HotelInfoRepo.HotelFacilityList(id),
                            HotelInfo                            = _HotelInfoRepo.HotelInfoLists(id),
                            HotelContactInfo                     = _ContactRepo.HotelContactInfoHotelId(id),
                            HotelCityInfo                        = _HotelInfoRepo.HotelCityList(id),
                            HotelCityInfoList                    = _CityInfoRepo.HotelCityInfoList(),
                            CountryList                          = _HotelInfoRepo.GetCountryList(),
                            HotelAdditionalChargeList            = _AdditionalChargeRepo.HotelAdditionalChargeList(),
                            HotelAdditionalChargeAssociationList = _HotelInfoRepo.HotelAdditionalChargeList(id),
                            DesignationList                      = _DesignationRepo.HotelDesignationList(),
                            CountryId                            = model.HotelInfo.CountryId,
                            // HotelTypeList = _HotelInfoRepo.GetHotelTypeList(),
                        };
                        //return RedirectToAction("Edit", viewModel);
                    }

                    else
                    {
                        q.HotelId  = Hotelid;
                        q.ChargeId = Convert.ToInt32(strs);
                        _HotelInfoRepo.HotelAdditionalChargeAssociationEdit(q);
                    }
                }

                Htl_HotelFacilityAssociation r = new Htl_HotelFacilityAssociation();
                p.HotelId = Hotelid;
                _HotelInfoRepo.DeleteFacilityList(id);
                HotelInfos recordToEdited;
                recordToEdited = _HotelInfoRepo.HotelInfoById(id);
                string[] strig = strHotelFacityList.Split(',');
                foreach (string strs in strig)
                {
                    if (string.IsNullOrEmpty(strs))
                    {
                        var viewModel = new HotelInfos
                        {
                            HotelRoomTypeList            = _RoomTypeRepo.HotelRoomTypeList(),
                            HotelRoomTypeAssociationList = _HotelInfoRepo.HotelRoomTypeList(id),
                            HotelFacityList = _FacilityRepo.HotelFacilityList(),
                            HotelFacilityAssociationList = _HotelInfoRepo.HotelFacilityList(id),
                            HotelInfo                            = _HotelInfoRepo.HotelInfoLists(id),
                            HotelContactInfo                     = _ContactRepo.HotelContactInfoHotelId(id),
                            HotelCityInfo                        = _HotelInfoRepo.HotelCityList(id),
                            HotelCityInfoList                    = _CityInfoRepo.HotelCityInfoList(),
                            CountryList                          = _HotelInfoRepo.GetCountryList(),
                            HotelAdditionalChargeList            = _AdditionalChargeRepo.HotelAdditionalChargeList(),
                            HotelAdditionalChargeAssociationList = _HotelInfoRepo.HotelAdditionalChargeList(id),
                            DesignationList                      = _DesignationRepo.HotelDesignationList(),
                            CountryId                            = model.HotelInfo.CountryId,
                            // HotelTypeList = _HotelInfoRepo.GetHotelTypeList(),
                        };
                        //return RedirectToAction("Edit", viewModel);
                    }

                    else
                    {
                        r.HotelId    = Hotelid;
                        r.FacilityId = Convert.ToInt32(strs);
                        _HotelInfoRepo.HotelFacilityAssociationEdit(r);
                    }
                }

                Htl_RoomTypeAssociation s = new Htl_RoomTypeAssociation();
                p.HotelId = Hotelid;
                _HotelInfoRepo.DeleteRoomTypeList(id);
                HotelInfos recordToEdits;
                recordToEdits = _HotelInfoRepo.HotelInfoById(id);
                string[] strng = strHotelRoomTypeList.Split(',');
                foreach (string strs in strng)
                {
                    if (string.IsNullOrEmpty(strs))
                    {
                        var viewModel = new HotelInfos
                        {
                            HotelRoomTypeList            = _RoomTypeRepo.HotelRoomTypeList(),
                            HotelRoomTypeAssociationList = _HotelInfoRepo.HotelRoomTypeList(id),
                            HotelFacityList = _FacilityRepo.HotelFacilityList(),
                            HotelFacilityAssociationList = _HotelInfoRepo.HotelFacilityList(id),
                            HotelInfo                            = _HotelInfoRepo.HotelInfoLists(id),
                            HotelContactInfo                     = _ContactRepo.HotelContactInfoHotelId(id),
                            HotelCityInfo                        = _HotelInfoRepo.HotelCityList(id),
                            HotelCityInfoList                    = _CityInfoRepo.HotelCityInfoList(),
                            CountryList                          = _HotelInfoRepo.GetCountryList(),
                            HotelAdditionalChargeList            = _AdditionalChargeRepo.HotelAdditionalChargeList(),
                            HotelAdditionalChargeAssociationList = _HotelInfoRepo.HotelAdditionalChargeList(id),
                            DesignationList                      = _DesignationRepo.HotelDesignationList(),
                            CountryId                            = model.HotelInfo.CountryId,
                            // HotelTypeList = _HotelInfoRepo.GetHotelTypeList(),
                        };
                        //return RedirectToAction("Edit", viewModel);
                    }

                    else
                    {
                        s.HotelId         = Hotelid;
                        s.HotelRoomTypeId = Convert.ToInt32(strs);
                        _HotelInfoRepo.HotelRoomTypeAssociationEdit(s);
                    }
                }


                ViewData["success"] = "Record successfully edited.";

                /// return to view after success

                /// recordToEdit = _HotelInfoRepo.HotelInfoById(id);

                var viewModel1 = new HotelInfos
                {
                    HotelRoomTypeList            = _RoomTypeRepo.HotelRoomTypeList(),
                    HotelRoomTypeAssociationList = _HotelInfoRepo.HotelRoomTypeList(id),
                    HotelFacityList = _FacilityRepo.HotelFacilityList(),
                    HotelFacilityAssociationList = _HotelInfoRepo.HotelFacilityList(id),
                    HotelInfo                            = _HotelInfoRepo.HotelInfoLists(id),
                    HotelContactInfo                     = _ContactRepo.HotelContactInfoHotelId(id),
                    HotelCityInfo                        = _HotelInfoRepo.HotelCityList(id),
                    HotelAdditionalChargeList            = _AdditionalChargeRepo.HotelAdditionalChargeList(),
                    HotelAdditionalChargeAssociationList = _HotelInfoRepo.HotelAdditionalChargeList(id),
                    DesignationList                      = _DesignationRepo.HotelDesignationList(),
                    CountryId                            = model.CountryId,
                    HotelCityInfoList                    = _CityInfoRepo.HotelCityInfoList(),
                    CountryList                          = _HotelInfoRepo.GetCountryList(),
                    // HotelTypeList = _HotelInfoRepo.GetHotelTypeList(),
                };
                ViewData["success"] = "Record successfully edited.";
                return(View("Edit", viewModel1));
            }
        }