public JsonResult SaveAttendance(AttendanceViewModel viewModel)
        {
            var cmsResult = new CMSResult();

            if (ModelState.IsValid)
            {
                cmsResult = _attendanceService.Save(new Attendance
                {
                    ClassId           = viewModel.ClassId,
                    BatchId           = viewModel.BatchId,
                    Date              = viewModel.Date,
                    Activity          = viewModel.Activity,
                    UserId            = viewModel.UserId,
                    StudentAttendence = viewModel.StudentAttendence,
                    BranchId          = viewModel.BranchId,
                    IsManual          = true
                });
                if (cmsResult.Success)
                {
                    var bodySubject = "Web portal - Attendance create";
                    var batch       = _batchService.GetBatcheById(viewModel.BatchId);
                    var batchTime   = "( " + batch.InTime.ToShortTimeString() + " To " + batch.OutTime.ToShortTimeString() + " )";
                    var message     = "Class Name : " + viewModel.ClassName + " <br/>Batch Name : " + viewModel.BatchName + " " + batchTime
                                      + "Attendance Date" + viewModel.Date.ToString("dd/MM/yyyy") + "<br/>Attendance created successfully";
                    SendMailToAdmin(message, bodySubject);
                }
            }
            else
            {
                var errors = ModelState.Values.SelectMany(x => x.Errors).ToArray();
                foreach (var item in errors)
                {
                    cmsResult.Results.Add(new Result {
                        Message = item.ErrorMessage, IsSuccessful = false
                    });
                }
            }
            return(Json(cmsResult, JsonRequestBehavior.AllowGet));
        }
Beispiel #2
0
        public ActionResult Edit(int id)
        {
            ViewBag.SelectedClass = from mt in _classService.GetClasses()
                                    select new SelectListItem
            {
                Value = mt.ClassId.ToString(),
                Text  = mt.Name
            };

            var projection = _batchService.GetBatcheById(id);

            if (projection == null)
            {
                _logger.Warn(string.Format("Batch does not Exists {0}.", id));
                Warning("Batch does not Exists.");
                return(RedirectToAction("Index"));
            }
            ViewBag.ClassId = projection.ClassId;

            var viewModel = AutoMapper.Mapper.Map <BatchProjection, BatchViewModel>(projection);

            return(View(viewModel));
        }