public IActionResult DeleteSpecialization(AddSpecialization vm)
        {
            var NameExist = _auc.Specializations.ToList().Any(u => u.Name == vm.Specialization);

            if (NameExist)
            {
                var SpecializationName = _auc.Specializations.Where(f => f.Name == vm.Specialization)
                                         .Select(s => s.Id).Single();

                var model = _auc.Specializations.Find(SpecializationName);
                _auc.Remove(model);

                _auc.SaveChanges();
                ViewBag.Success = "Specialization code is deleted successfully";
                return(View());
            }
            else
            {
                ViewBag.fail = "This Specialization doesn't exist";
                return(View());
            }
        }
        public IActionResult AddSpecialization(AddSpecialization obj)
        {
            Specialization b = new Specialization();

            b.Name = obj.Specialization;
            b.Code = obj.Code;
            var NameExist = _auc.Specializations.ToList().Any(u => u.Name == b.Name);
            var CodeExist = _auc.Specializations.ToList().Any(u => u.Code == b.Code);

            if (CodeExist)
            {
                ViewBag.Fail = "This code is already taken.";
                return(View());
            }
            else if (NameExist)
            {
                ViewBag.Fail2 = "This specialization already exists.";
                return(View());
            }
            else
            {
                var code   = b.Code;
                int _Index = (int)code[0] - 48;
                if (_Index == 1)
                {
                    _auc.Add(b);
                    _auc.SaveChanges();
                    ViewBag.Success = "Specialization is added successfully";
                }
                else
                {
                    ViewBag.Fail3 = "Your code must start with 1";
                }
                return(View());
            }
        }
示例#3
0
        private void button2_Click(object sender, EventArgs e)
        {
            AddSpecialization Specialization = new AddSpecialization();

            Specialization.ShowDialog();
        }