public PersonnelSematMantagheViewModel(KhadamatMashiniPersonnel personnel)
 {
     Id           = personnel.Id;
     SematId      = personnel.SematId;
     ManateghId   = personnel.ManateghId;
     Name         = personnel.Name;
     TelDakheli   = personnel.TelDakheli;
     TelMostaghim = personnel.TelMostaghim;
     Mobile       = personnel.Mobile;
 }
        public ActionResult Save(PersonnelSematMantagheViewModel personnel)
        {
            if (!ModelState.IsValid)
            {
                personnel.Semats    = _db.Semats.ToList();
                personnel.Manateghs = _db.Manateghs.ToList();
                return(View("PersonnelForm", personnel));
            }

            if (personnel.Id == 0)
            {
                var khMashini = new KhadamatMashiniPersonnel();
                Mapper.Map <PersonnelSematMantagheViewModel, KhadamatMashiniPersonnel>(personnel, khMashini);
//                khMashini.Id = personnel.Id;
//                khMashini.Name = personnel.Name;
//                khMashini.SematId = personnel.SematId;
//                khMashini.TelDakheli = personnel.TelDakheli;
//                khMashini.TelMostaghim = personnel.TelMostaghim;
//                khMashini.Mobile = personnel.Mobile;
//                khMashini.ManateghId = personnel.ManateghId;

                _db.KhadamatMashiniPersonnels.Add(khMashini);
            }
            else
            {
                var personnelInDb = _db.KhadamatMashiniPersonnels.Single(k => k.Id == personnel.Id);
                Mapper.Map <PersonnelSematMantagheViewModel, KhadamatMashiniPersonnel>(personnel, personnelInDb);
//                personnelInDb.Name = personnel.Name;
//                personnelInDb.SematId = personnel.SematId;
//                personnelInDb.TelDakheli = personnel.TelDakheli;
//                personnelInDb.TelMostaghim = personnel.TelMostaghim;
//                personnelInDb.Mobile = personnel.Mobile;
//                personnelInDb.ManateghId = personnel.ManateghId;
            }

            _db.SaveChanges();

            return(RedirectToAction("Index", "Personnel"));
        }