Beispiel #1
0
        public ActionResult TechnicianProfileEdit(TechnicianProfile model, HttpPostedFileBase newImage)
        {
            //check if the image is null and convert to byte array
            if (newImage != null)
            {
                model.TechPicture = new byte[newImage.ContentLength];
                newImage.InputStream.Read(model.TechPicture, 0, newImage.ContentLength);
            }

            //check if the model state is valid and add the new updated profile to database
            if (ModelState.IsValid)
            {
                using (var db = new ApplicationDbContext())
                {
                    db.Entry(model).State = EntityState.Modified;
                    db.SaveChanges();
                }
            }

            //get the new profile from database and return the view with the profile
            using (var db = new ApplicationDbContext())
            {
                var profile = db.TechnicianProfiles.Find(model.Id);
                return(View(profile));
            }
        }
Beispiel #2
0
        public ActionResult TechnicianHome()
        {
            //if this is the users first time logging in as a technician, create teachnician and technicianProfile in database
            //get the technicians user ID
            var uid = repo.getUserId();

            //var uid = User.Identity.GetUserId();

            if (TempData["techReg"] != null)
            {
                //create instance of registerview model
                TechnicianRegisterViewModel trvm = new TechnicianRegisterViewModel();
                //pass it to a temp variable
                trvm = (TechnicianRegisterViewModel)TempData["techReg"];

                //creaet new technician and technician profile in database for suer
                //check to see if user has already been added
                var tech = repo.GetTechByUserId(uid);
                if (tech == null)
                {
                    //create technician from viewmodel and add to database
                    Technician model = new Technician()
                    {
                        CompanyName        = trvm.CompanyName,
                        CEOFirstName       = trvm.CEOFirstName,
                        CEOLastName        = trvm.CEOLastName,
                        JobType            = trvm.JobType,
                        AspNetUser_Id      = uid,
                        ApplicationUser_Id = uid
                    };

                    repo.PostTech(model);
                }

                //get info to load onto page
                TechnicianProfile profile = new TechnicianProfile();

                //get default picture from resources and convert to Image object called defaultPic
                MemoryStream msNew      = new MemoryStream();
                Image        defaultPic = Resources.DefaultProfilePic;
                defaultPic.Save(msNew, System.Drawing.Imaging.ImageFormat.Jpeg);

                //find the technician currently logged in
                var newtech = repo.GetTechByUserId(uid);

                //add info to TechnicianProfile object to insert into database
                profile.techId      = newtech.Id;
                profile.Description = "Add your company's description here";
                profile.Rating      = "0";
                //convert Image object to byteArray
                profile.TechPicture = msNew.ToArray();

                //close stream and save TechnicianProfile to database
                msNew.Close();
                repo.PostTechProfile(profile);

                return(View(profile));
            }
            else
            {
                //if is not the users first time logging in
                //get tech id of the current user logged in
                var techid = repo.GetTechIdByUserId(uid);
                //get the profile associated with the user
                var profile = repo.GetTechProfileByTechId(techid);

                return(View(profile));
            }
        }
Beispiel #3
0
 public void PostTechProfile(TechnicianProfile profile)
 {
     db.TechnicianProfiles.Add(profile);
     db.SaveChanges();
 }
 public void PostTechProfile(TechnicianProfile profile)
 {
 }