public ActionResult Create([DataSourceRequest] DataSourceRequest request, CertificateViewModel model)
        {
            var newModel = model;
            if (model != null && ModelState.IsValid)
            {
                var certificate = new Certificate()
                {
                    Title = model.Title,
                    IssueDate = DateTime.Now,
                    MinimalMark = model.MinimalMark
                };

                string[] newCertificateCourses = model.Courses.Split(',');

                if (newCertificateCourses.Length > 1)
                {
                    foreach (var item in newCertificateCourses)
                    {
                        var certificateCourse = this.Data.Courses.All().FirstOrDefault(c => c.Title.Equals(item,StringComparison.InvariantCultureIgnoreCase));
                        certificate.Courses.Add(certificateCourse);
                    }
                }
                else
                {
                    var courseTitle = newCertificateCourses[0];
                    var certificateCourse = this.Data.Courses.All().FirstOrDefault(c => c.Title.Equals(courseTitle,StringComparison.InvariantCultureIgnoreCase));
                    certificate.Courses.Add(certificateCourse);
                }

                this.Data.Certificates.Add(certificate);
                this.Data.SaveChanges();

                newModel = this.FromCertificate(certificate);
            }

            return Json(new[] { newModel }.ToDataSourceResult(request, ModelState));
        }
        private CertificateViewModel FromCertificate(Certificate certificate)
        {
            var model = new CertificateViewModel();
            model.Id = certificate.Id;
            model.Title = certificate.Title;
            model.MinimalMark = certificate.MinimalMark;

            StringBuilder sb = new StringBuilder();
            foreach (var item in certificate.Courses)
            {
                sb.Append(item.Title + ",");
            }
            if (sb.Length > 0)
            {
                sb.Length--;
            }

            model.Courses = sb.ToString();

            return model;
        }