Esempio n. 1
0
        public NewGuideModel(guide guide)
        {
            foreach (var propertyInfo in guide.GetType().GetProperties())
            {
                if (propertyInfo.PropertyType.IsValueType || propertyInfo.PropertyType.Name == "String")
                {
                    propertyInfo.SetValue(this, propertyInfo.GetValue(guide));
                }
            }
            Email              = guide.user.Email;
            Password           = guide.user.Password;
            Deleted            = guide.user.Deleted;
            PermittedCountries = new List <int>();
            PermittedCities    = new List <int>();
            //PermittedRegions = new List<int>();
            foreach (var countryPermission in guide.user.country_permission)
            {
                PermittedCountries.Add(countryPermission.country.Id);
            }

            /*foreach (var regionPermission in guide.user.region_permission)
             * {
             *  PermittedRegions.Add(regionPermission.region.Id);
             * }*/
            foreach (var cityPermission in guide.user.city_permission)
            {
                PermittedCities.Add(cityPermission.city.Id);
            }
        }
Esempio n. 2
0
        public ActionResult DeleteConfirmed(int id)
        {
            guide guide = db.guide.Find(id);

            db.guide.Remove(guide);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
Esempio n. 3
0
 public ActionResult Edit([Bind(Include = "guideId,guideName,guidetype,registerDate")] guide guide)
 {
     if (ModelState.IsValid)
     {
         db.Entry(guide).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(guide));
 }
Esempio n. 4
0
 public void CopyTo(ref guide guide)
 {
     foreach (var propertyInfo in guide.GetType().GetProperties())
     {
         if (!propertyInfo.Name.Contains("Id") && (propertyInfo.PropertyType.IsValueType || propertyInfo.PropertyType.Name == "String"))
         {
             propertyInfo.SetValue(guide, propertyInfo.GetValue(this));
         }
     }
     guide.EditorId = EditorId;
 }
Esempio n. 5
0
        public ActionResult Create([Bind(Include = "guideId,guideName,guidetype,registerDate")] guide guide)
        {
            if (ModelState.IsValid)
            {
                db.guide.Add(guide);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(guide));
        }
Esempio n. 6
0
        // GET: guides/Delete/5
        public ActionResult Delete(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            guide guide = db.guide.Find(id);

            if (guide == null)
            {
                return(HttpNotFound());
            }
            return(View(guide));
        }
Esempio n. 7
0
        public void AddNewGuide(NewGuideModel model)
        {
            model.Email = StringTransformationProvider.TransformEmail(model.Email);
            if (_db.user.Any(u => u.Email == model.Email))
            {
                throw new MyException(Errors.UserExists);
            }
            var trans = _db.Database.BeginTransaction();

            try
            {
                var newUser = new user
                {
                    Guid       = Guid.NewGuid().ToString(),
                    Password   = StringTransformationProvider.Md5(model.Password),
                    Email      = model.Email,
                    UserTypeId = GetUserTypeByTag(UserTypes.Guide),
                    Deleted    = model.Deleted
                };
                _db.user.Add(newUser);
                _db.SaveChanges();
                var newEditor = new guide();
                model.CopyTo(ref newEditor);
                newEditor.UserId = newUser.Id;
                _db.guide.Add(newEditor);
                _db.country_permission.AddRange(
                    model.PermittedCountries.Select(c => new country_permission {
                    CountryId = c, UserId = newUser.Id
                }));
                _db.city_permission.AddRange(
                    model.PermittedCities.Select(c => new city_permission {
                    CityId = c, UserId = newUser.Id
                }));
                //                _db.region_permission.AddRange(
                //                    model.PermittedRegions.Select(c => new region_permission {RegionId = c, UserId = newUser.Id}));

                _db.SaveChanges();
                trans.Commit();
            }
            catch (Exception)
            {
                trans.Rollback();
                throw;
            }
        }