Example #1
0
        public ActionResult Add([Bind(Include = "Id,Name,Description,TypeId,SelectedOrganizationStr,SelectedProcessesStr")] AddActivityViewModel AddObj)
        {
            if (!ModelState.IsValid)
            {
                var OrgsObj = DMLObj.GetOrganizationList();
                ViewBag.AllOrganizations = AutoMapper.Mapper.Map <IEnumerable <AMOrganization>, IEnumerable <JsonOrganizationViewModel> >(OrgsObj);
                ViewBag.ActivityTypes    = DMLObj.GetAllActivityTypes();
                var ProcessObj = DMLObj.GetProcessList();
                ViewBag.AllProcesses = AutoMapper.Mapper.Map <IEnumerable <AMProcess>, IEnumerable <JsonProcessViewModel> >(ProcessObj);
                return(View(AddObj));
            }
            var OrgsList = DMLObj.FindOrgsForAddActivityByStringIds(AddObj.SelectedOrganizationStr);

            if (OrgsList.Count() == 0)
            {
                var OrgsObj = DMLObj.GetOrganizationList();
                ViewBag.AllOrganizations = AutoMapper.Mapper.Map <IEnumerable <AMOrganization>, IEnumerable <JsonOrganizationViewModel> >(OrgsObj);
                ViewBag.ActivityTypes    = DMLObj.GetAllActivityTypes();
                var ProcessObj = DMLObj.GetProcessList();
                ViewBag.AllProcesses = AutoMapper.Mapper.Map <IEnumerable <AMProcess>, IEnumerable <JsonProcessViewModel> >(ProcessObj);

                ModelState.AddModelError("SelectedOrganizationStr", "هیچ سازمان معتبری انتخاب نشده است");
                return(View(AddObj));
            }
            var ProcessesList = DMLObj.FindProcessesForAddActivityByStringIds(AddObj.SelectedProcessesStr);

            if (ProcessesList.Count() == 0)
            {
                var OrgsObj = DMLObj.GetOrganizationList();
                ViewBag.AllOrganizations = AutoMapper.Mapper.Map <IEnumerable <AMOrganization>, IEnumerable <JsonOrganizationViewModel> >(OrgsObj);
                ViewBag.ActivityTypes    = DMLObj.GetAllActivityTypes();
                var ProcessObj = DMLObj.GetProcessList();
                ViewBag.AllProcesses = AutoMapper.Mapper.Map <IEnumerable <AMProcess>, IEnumerable <JsonProcessViewModel> >(ProcessObj);

                ModelState.AddModelError("SelectedProcessesStr", "هیچ فرآیند معتبری انتخاب نشده است");
                return(View(AddObj));
            }
            var selectedActType = DMLObj.GetActivityTypeById(AddObj.TypeId);

            if (selectedActType == null)
            {
                var OrgsObj = DMLObj.GetOrganizationList();
                ViewBag.AllOrganizations = AutoMapper.Mapper.Map <IEnumerable <AMOrganization>, IEnumerable <JsonOrganizationViewModel> >(OrgsObj);
                ViewBag.ActivityTypes    = DMLObj.GetAllActivityTypes();
                var ProcessObj = DMLObj.GetProcessList();
                ViewBag.AllProcesses = AutoMapper.Mapper.Map <IEnumerable <AMProcess>, IEnumerable <JsonProcessViewModel> >(ProcessObj);

                ModelState.AddModelError("TypeId", "هیچ نوع فعالیت معتبری انتخاب نشده است");
                return(View(AddObj));
            }
            bool resAdd        = false;
            var  addedActivity = DMLObj.AddNewActivity(new AMActivity {
                Name = AddObj.Name, Description = AddObj.Description, ActivityItems = null, TypeId = AddObj.TypeId, Type = selectedActType
            }, out resAdd);

            if (resAdd && DMLObj.AddNewActivityRelation(OrgsList, ProcessesList, addedActivity) > 0)
            {
                return(View("Success"));
            }

            var OrgsObjp = DMLObj.GetOrganizationList();

            ViewBag.AllOrganizations = AutoMapper.Mapper.Map <IEnumerable <AMOrganization>, IEnumerable <JsonOrganizationViewModel> >(OrgsObjp);
            ViewBag.ActivityTypes    = DMLObj.GetAllActivityTypes();
            var ProcessObjp = DMLObj.GetProcessList();

            ViewBag.AllProcesses = AutoMapper.Mapper.Map <IEnumerable <AMProcess>, IEnumerable <JsonProcessViewModel> >(ProcessObjp);

            return(View("Error"));
        }