Ejemplo n.º 1
0
        public async System.Threading.Tasks.Task <JsonResult> AddHocVien(HopDongDOLABHocVienMappingViewModel model)
        {
            var hopDongDOLABHocVienMappingService = this.Service <IHopDongDOLABHocVienMappingService>();
            var entity = await hopDongDOLABHocVienMappingService.GetByIdHopDongDOLABAndIdTTCNAsync(model.IdHopDongDOLAB.GetValueOrDefault(), model.IdThongTinCaNhan.GetValueOrDefault());

            if (entity == null)
            {
                await hopDongDOLABHocVienMappingService.CreateAsync(model.ToEntity());

                return(Json(new { success = true, message = "Thêm thành công!" }, JsonRequestBehavior.AllowGet));
            }
            try
            {
                if (entity.Active == true)
                {
                    return(Json(new { success = false, message = "Đã tồn tại học viên này!" }, JsonRequestBehavior.AllowGet));
                }
                else
                {
                    entity.Active = true;
                    await hopDongDOLABHocVienMappingService.UpdateAsync(entity);

                    string controllerName = this.ControllerContext.RouteData.Values["controller"].ToString();
                    var    result         = await new SystemLogController().Create("Thêm học viên vào HĐ", controllerName, entity.Id);
                    return(Json(new { success = true, message = "Thêm thành công!" }, JsonRequestBehavior.AllowGet));
                }
            }
            catch (Exception e)
            {
                return(Json(new { success = false, message = Resource.ErrorMessage }));
            }
        }
Ejemplo n.º 2
0
        public async System.Threading.Tasks.Task <ActionResult> Create(HopDongDOLABEditViewModel model)
        {
            var hopDongDOLABService = this.Service <IHopDongDOLABService>();
            var hopDongDOLABHocVienMappingService = this.Service <IHopDongDOLABHocVienMappingService>();

            try
            {
                var entity = model.ToEntity();
                entity.Active = true;
                await hopDongDOLABService.CreateAsync(entity);

                string controllerName = this.ControllerContext.RouteData.Values["controller"].ToString();
                var    result         = await new SystemLogController().Create("Tạo hợp đồng", controllerName, entity.Id);
                var    idHopDongDOLAB = entity.Id;
                try
                {
                    foreach (var item in model.SelectedThongTinCaNhan)
                    {
                        var mapping = new HopDongDOLABHocVienMappingViewModel()
                        {
                            IdHopDongDOLAB   = idHopDongDOLAB,
                            IdThongTinCaNhan = item,
                        };
                        await hopDongDOLABHocVienMappingService.CreateAsync(mapping.ToEntity());
                    }
                    return(Json(new { success = true, message = "Tạo thành công" }));
                }
                catch (Exception e)
                {
                    await hopDongDOLABService.DeleteAsync(entity);

                    var listMapping = hopDongDOLABHocVienMappingService.GetByIdHopDongDOLAB(idHopDongDOLAB).ToList();
                    foreach (var item in listMapping)
                    {
                        await hopDongDOLABHocVienMappingService.DeleteAsync(item);
                    }
                    return(Json(new { success = false, message = Resource.ErrorMessage }));
                }
            }
            catch (Exception e)
            {
                return(Json(new { success = false, message = Resource.ErrorMessage }));
            }
        }