public ActionResult Edit(UserViewModel uv)
        {
            User usr = new RouteOptimization.Infrastructure.User();
            //userid , addressid
            usr.UserID = uv.UserId;
            usr.EmailID = uv.EmailID;
            usr.FirstName = uv.FirstName;
            usr.LastName = uv.LastName;
            usr.Phone = uv.Phone;
            usr.UserTypeID = uv.UserTypeId;
            usr.AddressID = uv.AddressID;

            Address ad = new Address();
            ad.Address1 = uv.Address1;
            ad.Address2 = uv.Address2;
            ad.PostalCode = uv.PostalCode;
            ad.CityID = uv.CityId;
            ad.CountryID = uv.CountryId;
            ad.ProvinceID = uv.ProvinceId;
            ad.AddressID = uv.AddressID;

            //     ad.CityID = RedeemTransaction.CityDetails;
            //    ad.CountryID = RedeemTransaction.CountryDetails;
            //     ad.ProvinceID = RedeemTransaction.ProvinceDetails;
            int i = 0;
            int addid = 0;
            if (ModelState.IsValid)
            {
                db.Entry(ad).State = EntityState.Modified;
                //  db.Addresses.Add(ad);
                i = db.SaveChanges();
                var result = db.Addresses.OrderByDescending(x => x.AddressID).First();
                addid = result.AddressID;
            }
            if (ModelState.IsValid)
            {
                if (addid != 0)
                {
                    // usr.AddressID = addid;
                    db.Entry(usr).State = EntityState.Modified;
                    db.SaveChanges();
                    return RedirectToAction("Create");
                }
            }

            //   ViewBag.UserTypeID = new SelectList(db.UserTypes, "UserTypeID", "Description");
            return View(uv);//user);
            //      db.Entry(user).State = EntityState.Modified;
            //    db.SaveChanges();
            //  return RedirectToAction("Index");
            // }
            // ViewBag.UserTypeId = new SelectList(db.UserTypes, "UserTypeID", "Description", user.UserTypeID);
            // return View(user);
        }
        public ActionResult Create(UserViewModel uv)
        {
            User usr = new RouteOptimization.Infrastructure.User();
            usr.EmailID = uv.EmailID;
            usr.FirstName = uv.FirstName;
            usr.LastName = uv.LastName;
            usr.Phone = uv.Phone;
            usr.UserTypeID = uv.UserTypeId;

            Address ad = new Address();
            ad.Address1 = uv.Address1;
            ad.Address2 = uv.Address2;
            ad.PostalCode = uv.PostalCode;
            ad.CityID = uv.CityId;
            ad.CountryID = uv.CountryId;
            ad.ProvinceID = uv.ProvinceId;

            //     ad.CityID = RedeemTransaction.CityDetails;
            //    ad.CountryID = RedeemTransaction.CountryDetails;
            //     ad.ProvinceID = RedeemTransaction.ProvinceDetails;
            // int i=0;

            Login lg = new Login();
            lg.UserName = uv.EmailID;
            lg.Password = uv.EmailID;
            lg.UserTypeID = uv.UserTypeId;

            int addid = 0;
            if (ModelState.IsValid)
            {
                ud.AddAddress(ad);
                var result = db.Addresses.OrderByDescending(x => x.AddressID).First();
                addid = result.AddressID;
            }

            if (ModelState.IsValid)
            {
                if (addid != 0)
                {
                    usr.AddressID = addid;
                    ud.AddUser(usr);
                }
            }

            if (ModelState.IsValid)
            {
                var res = db.Users.OrderByDescending(x => x.UserID).First();
                lg.UserID = res.UserID;

                ud.AddLogin(lg);
            }

            if (ModelState.IsValid)
            {
                UserAvailability ua = new UserAvailability();
                ua.UserID = usr.UserID;
                ua.Status = "AV";
                ud.AddUAvail(ua);
                return RedirectToAction("Create");
            }

            //   ViewBag.UserTypeID = new SelectList(db.UserTypes, "UserTypeID", "Description");
            return View(uv);//user);
        }
Esempio n. 3
0
 public void AddUser(User ud)
 {
     db.Users.Add(ud);
     db.SaveChanges();
 }