Ejemplo n.º 1
0
        public JsonResult Action(AccomodationPackagesActionModel model)
        {
            JsonResult json   = new JsonResult();
            var        result = false;

            if (model.ID > 0)
            {
                var accomodationPackage = accomodationPackagesService.GetAllAccomodationPackageByID(model.ID);
                accomodationPackage.Name        = model.Name;
                accomodationPackage.NoOfRoom    = model.NoOfRoom;
                accomodationPackage.FeePerNight = model.FeePerNight;
                result = accomodationPackagesService.UpdateAccomodationPackage(accomodationPackage);
            }
            else
            {
                AccommodationPackage accomodationPackage = new AccommodationPackage();
                accomodationPackage.Name        = model.Name;
                accomodationPackage.NoOfRoom    = model.NoOfRoom;
                accomodationPackage.FeePerNight = model.FeePerNight;
                result = accomodationPackagesService.SaveAccomodationPackage(accomodationPackage);
            }

            if (result)
            {
                json.Data = new { Sucess = true };
            }
            else
            {
                json.Data = new { Sucess = false, Message = "Unable to perform action on Accomodation type" };
            }
            return(json);
        }
Ejemplo n.º 2
0
        public JsonResult Action(AccommodationPackageActionModel model)
        {
            JsonResult json = new JsonResult();

            var result = false;

            //model.PictureIDs = "90,32,22" = ["90", "32", "22"] = {90, 32, 22}
            List <int> pictureIDs = !string.IsNullOrEmpty(model.PictureIDs) ? model.PictureIDs.Split(',').Select(x => int.Parse(x)).ToList() : new List <int>();
            var        pictures   = _dashboardService.GetPicturesByIDs(pictureIDs);


            // trying to edit a record
            if (model.ID > 0)
            {
                var accommodationPackage = _accommodationPackagesService.GetAccommodationPackageById(model.ID);

                accommodationPackage.AccommodationTypeID = model.AccommodationTypeID;
                accommodationPackage.Name        = model.Name;
                accommodationPackage.NoOfRoom    = model.NoOfRoom;
                accommodationPackage.FeePerNight = model.FeePerNight;

                accommodationPackage.AccommodationPackagePictures.Clear();
                accommodationPackage.AccommodationPackagePictures.AddRange(pictures.Select(x => new AccommodationPackagePicture()
                {
                    AccommodationPackageID = accommodationPackage.ID, PictureID = x.ID
                }));

                result = _accommodationPackagesService.UpdateAccommodationPackage(accommodationPackage);
            }
            // trying to create a record
            else
            {
                AccommodationPackage accommodationPackage = new AccommodationPackage();

                accommodationPackage.AccommodationTypeID = model.AccommodationTypeID;
                accommodationPackage.Name        = model.Name;
                accommodationPackage.NoOfRoom    = model.NoOfRoom;
                accommodationPackage.FeePerNight = model.FeePerNight;

                accommodationPackage.AccommodationPackagePictures = new List <AccommodationPackagePicture>();
                accommodationPackage.AccommodationPackagePictures.AddRange(pictures.Select(x => new AccommodationPackagePicture()
                {
                    PictureID = x.ID
                }));

                result = _accommodationPackagesService.SaveAccommodationPackage(accommodationPackage);
            }

            if (result)
            {
                json.Data = new { Success = true };
            }
            else
            {
                json.Data = new { Success = false, Message = "Unable to perform action on Accommodation Package." };
            }

            return(json);
        }
Ejemplo n.º 3
0
        public bool SaveAccommodationPackage(AccommodationPackage accommodationPackage)
        {
            var context = new PMSContext();

            context.AccommodationPackages.Add(accommodationPackage);

            return(context.SaveChanges() > 0);
        }
        public bool DeleteAccomodationPackage(AccommodationPackage accomodationPackage)
        {
            var context = new HMSContext();

            context.Entry(accomodationPackage).State = System.Data.Entity.EntityState.Deleted;

            return(context.SaveChanges() > 0);
        }
 public bool UpdateAccommodationPackage(AccommodationPackage accommodationPackage)
 {
     var context = new HMSContext();
     var exitingAccommodationPackage = context.AccommodationPackages.Find(accommodationPackage.ID);
     context.AccommodationPackagePictures.RemoveRange(exitingAccommodationPackage.AccommodationPackagePictures);
     context.Entry(exitingAccommodationPackage).CurrentValues.SetValues(accommodationPackage);
     context.AccommodationPackagePictures.AddRange(accommodationPackage.AccommodationPackagePictures);
     return context.SaveChanges() > 0;
 }
Ejemplo n.º 6
0
 //delete accommodation package by id from db
 public bool DeleteAccommodationPackage(AccommodationPackage accommodationPackage)
 {
     if (accommodationPackage.AccommodationPackagePictures != null && accommodationPackage.AccommodationPackagePictures.Count != 0)
     {
         DeleteAccommdationPackagePictures(accommodationPackage.Id);
     }
     context.Entry(accommodationPackage).State = System.Data.Entity.EntityState.Deleted;
     return(context.SaveChanges() > 0);
 }
        public JsonResult Action(AccommodationPackageModel model)
        {
            var            result         = false;
            JsonResult     json           = new JsonResult();
            SharedServices sharedServices = new SharedServices();


            List <int> pictureIDs = !string.IsNullOrEmpty(model.PictureIDs)? model.PictureIDs.Split(',').Select(x => int.Parse(x)).ToList():new List <int>();
            var        pictures   = sharedServices.GetPictureByID(pictureIDs);

            if (model.ID > 0)//for Edit
            {
                var accommodationPackage = AccommodationPackagesServices.Instance.GetAccommodationPackageByID(model.ID);
                accommodationPackage.AccommodationTypeID = model.AccommodationTypeID;
                accommodationPackage.Name        = model.Name;
                accommodationPackage.FeePerNight = model.FeePerNight;
                accommodationPackage.NoOfRoom    = model.NoOfRoom;

                accommodationPackage.AccommodationPackagePictures.Clear();
                accommodationPackage.AccommodationPackagePictures.AddRange(pictures.Select(x => new AccommodationPackagePicture()
                {
                    AccommodationPackageID = model.ID, PictureID = x.ID
                }));

                result = AccommodationPackagesServices.Instance.UpdateAccommodationPackage(accommodationPackage);
            }
            else//for create
            {
                AccommodationPackage accommodationPackage = new AccommodationPackage();

                accommodationPackage.AccommodationTypeID = model.AccommodationTypeID;
                accommodationPackage.Name        = model.Name;
                accommodationPackage.FeePerNight = model.FeePerNight;
                accommodationPackage.NoOfRoom    = model.NoOfRoom;
                accommodationPackage.AccommodationPackagePictures = new List <AccommodationPackagePicture>();
                accommodationPackage.AccommodationPackagePictures.AddRange(pictures.Select(x => new AccommodationPackagePicture()
                {
                    PictureID = x.ID
                }));

                result = AccommodationPackagesServices.Instance.SaveAccommodationPackage(accommodationPackage);
            }

            if (result)
            {
                json.Data = new { Success = true };
            }
            else
            {
                json.Data = new { success = false, Message = "Unable to add Accommodationtype" };
            }
            return(json);
        }
Ejemplo n.º 8
0
        public bool DeleteAccommodationPackage(AccommodationPackage accommodationPackage)
        {
            var context = new PMSContext();


            var existingAccommodationPackage = context.AccommodationPackages.Find(accommodationPackage.ID);

            context.AccommodationPackagePictures.RemoveRange(existingAccommodationPackage.AccommodationPackagePicture);
            context.Entry(existingAccommodationPackage).State = System.Data.Entity.EntityState.Deleted;

            return(context.SaveChanges() > 0);
        }
        public JsonResult Action(AccommodationPackagesActionModel formModel)
        {
            bool result = false;

            //model.pictureIds = "22,23,24" => ["22","23","24"] => [22,23,24]
            var picsIds = !string.IsNullOrEmpty(formModel.PictureIds) ? formModel.PictureIds.Split(',').Select(int.Parse).ToList() : new List <int>();

            var pictures = DBServices.GetPicturesByIds(picsIds);

            if (formModel.Id == 0) //create
            {
                AccommodationPackage ap = new AccommodationPackage();

                ap.Name                = formModel.Name;
                ap.NoOfRoom            = formModel.NoOfRoom;
                ap.FeePerNight         = formModel.FeePerNight;
                ap.AccommodationTypeId = formModel.AccommodationTypeId;

                ap.AccommodationPackagePictures = new List <AccommodationPackagePicture>();
                ap.AccommodationPackagePictures.AddRange(pictures.Select(p => new AccommodationPackagePicture()
                {
                    PictureId = p.Id
                }));

                result = APServices.AddAccommodationPackage(ap);
            }
            else //edit
            {
                var ap = APServices.GetAccommodationPackageById(formModel.Id);

                ap.Name                = formModel.Name;
                ap.NoOfRoom            = formModel.NoOfRoom;
                ap.FeePerNight         = formModel.FeePerNight;
                ap.AccommodationTypeId = formModel.AccommodationTypeId;

                //delete existing accommodation pics to add new one after editing
                APServices.DeleteAccommdationPackagePictures(ap.Id);

                // in edit : need aPId to edit it not make a new one
                ap.AccommodationPackagePictures.AddRange(pictures.Select(p => new AccommodationPackagePicture()
                {
                    AccommodationPackageId = ap.Id,
                    PictureId = p.Id
                }));

                result = APServices.UpdateAccommodationPackage(ap);
            }

            return(JsonDataResult.Result(result));
        }
        public JsonResult Delete(AccommodationPackageModel model)
        {
            JsonResult json   = new JsonResult();
            var        result = false;

            AccommodationPackage accommodationPackage = new AccommodationPackage();

            accommodationPackage.ID = model.ID;
            result = AccommodationPackagesServices.Instance.DeleteAccommodationPackage(accommodationPackage);
            if (result)
            {
                json.Data = new { Success = true };
            }
            else
            {
                json.Data = new { success = false, Message = "Unable to add Accommodationtype" };
            }
            return(json);
        }
Ejemplo n.º 11
0
        //edit accommodation package in db
        public bool UpdateAccommodationPackage(AccommodationPackage accomodationPackage)
        {
            context.Entry(accomodationPackage).State = EntityState.Modified;

            return(context.SaveChanges() > 0);
        }
Ejemplo n.º 12
0
 //add accommodation package to db
 public bool AddAccommodationPackage(AccommodationPackage accommodationPackage)
 {
     context.AccommodationPackages.Add(accommodationPackage);
     return(context.SaveChanges() > 0);
 }