public ActionResult AddOrEditData(string sort, string order, string search, int pagesize, SpecialityGroup data)
        {
            try
            {
                if (data.Id != Guid.Empty)
                {
                    var row = context.SpecialityGroups.FirstOrDefault(x => x.Id == data.Id);
                    if (row == null)
                    {
                        return(Ok(new
                        {
                            success = false,
                            rowid = Guid.Empty,
                            page = 1,
                            message = "Не найден элемент для редактирования"
                        }));
                    }
                    row.Name      = data.Name;
                    row.ShortName = data.ShortName;
                    row.Code      = data.Code;
                }
                else
                {
                    data.Id = Guid.NewGuid();
                    context.SpecialityGroups.Add(data);
                }
                context.SaveChanges();

                var list      = SortData(context.SpecialityGroups, sort, order);
                int pageno    = 1;
                int idx       = -1;
                var idxsearch = list.FirstOrDefault(x => x.Id == data.Id);
                if (idxsearch != null)
                {
                    idx = list.ToList().IndexOf(idxsearch);
                }
                if (idx > -1 && pagesize != 0)
                {
                    pageno = idx / pagesize + 1;
                }

                return(Ok(new
                {
                    success = true,
                    rowid = data.Id,
                    page = pageno,
                    message = ""
                }));
            }
            catch (Exception ex)
            {
                return(StatusCode(StatusCodes.Status500InternalServerError, ex.Message));
            }
        }
Beispiel #2
0
        public JsonResult UpdateGroupData(int specialityId)
        {
            SpecialityGroup group = _repository.Specialities.FirstOrDefault(sp => sp.SpecialityId == specialityId).SpecialityGroup;

            return(Json(new { Id = group.SpecialityGroupId, Count = group.MaxNumOfSpec }));
        }