예제 #1
0
        public ActionResult GetEditSurvayView(int id)
        {
            try
            {
                var suray = _survayTypeService.GetSurvayTypeById(id);

                var model = _mapper.Map <SurvayTypeDto, SurvayTypeViewModel>(suray);
                return(PartialView("_EditorView", model));
            }
            catch (Exception e)
            {
                _log.Error($"Error :  {e}");
                return(Json(new { status = false, message = "UnSuccess ,Please try again" },
                            JsonRequestBehavior.AllowGet));
            }
        }
예제 #2
0
        public void InsertFieldDependant(IEnumerable <FieldDependantDto> dtos, int survayId)
        {
            try
            {
                var repo     = UnitOfWork.GetRepository <FieldDependant>();
                var entities = _mapper.Map <List <FieldDependantDto>, List <FieldDependant> >(dtos.ToList());

                var survay     = _survayTypeService.GetSurvayTypeById(survayId);
                var dependants = new List <int>();
                foreach (var d in survay.Fields)
                {
                    if (d.FieldDependants == null)
                    {
                        continue;
                    }
                    dependants.AddRange(d?.FieldDependants.Select(x => x.Id));
                    if (d.FieldDependants1 == null)
                    {
                        continue;
                    }
                    dependants.AddRange(d?.FieldDependants1.Select(x => x.Id));
                }

                //deleting non-existing in data base
                foreach (var e in dependants)
                {
                    if (!entities.Any(x => x.Id == e))
                    {
                        repo.Delete(e);
                    }
                }

                repo.AddorUpdate(entities);

                Save();
            }
            catch (Exception e)
            {
                _log.Error($"Error :  {e}");
                throw;
            }
        }