Пример #1
0
        public IActionResult CreateOrEdit([FromBody] NccEntity entity)
        {
            var tt    = "";
            var check = _nccService.GetAll().FirstOrDefault(j => j.TenNcc.Equals(entity.TenNcc));

            if (check != null)
            {
                return(Json("Đã có tên nhà cung cấp này , tạo mới thất bại"));
            }
            else
            {
                entity.CreateUserId = _getIdService.CreateIdUser();


                // insert
                var ouput = entity.MapTo <Ncc>();
                ouput.NgayGhi  = Fn.ParseDate(entity.NgayGhi);
                ouput.IsActive = true;
                ouput.Code     = entity.MasoThue;
                ouput.KeyUser  = _appService.AbpSession.UserId.ToString();
                ouput.NgaySinh = DateTime.Today;
                ouput.IdCty    = (int)IdCty();
                ouput.TenNcc   = entity.TenNcc;
                if (ModelState.IsValid)
                {
                    _nccService.CreateOrUpdate(ouput);
                }
            }


            return(Json(tt));
        }
Пример #2
0
        public IActionResult CreateOrEdit([FromBody] NccEntity entity)
        {
            var tt  = "";
            var com = _companyService.GetByCreatorUserId(IdCty());

            if (com != null)
            {
                if (entity.Id == 0)
                {
                    DateTime day;
                    try
                    {
                        day = DateTime.ParseExact(entity.NgayGhi, "yyyy-MM-dd'T'HH:mm:ss.fff'Z'", CultureInfo.InvariantCulture);
                    }
                    catch (Exception e)
                    {
                        day = DateTime.Parse(entity.NgayGhi);
                    }
                    // insert
                    var ouput = entity.MapTo <Ncc>();
                    ouput.NgayGhi  = day;
                    ouput.IsActive = true;
                    ouput.Code     = com.Code;
                    ouput.KeyUser  = _appService.AbpSession.UserId.ToString();
                    ouput.NgaySinh = DateTime.Today;
                    ouput.IdCty    = IdCty();
                    if (ModelState.IsValid)
                    {
                        _nccService.Create(ouput);
                    }

                    tt = "Tạo mới thành công";
                }
                else
                {
                    // update
                    var ouput = entity.MapTo <Ncc>();
                    ouput.NgayGhi  = DateTime.ParseExact(entity.NgayGhi, "yyyy-MM-dd'T'HH:mm:ss.fff'Z'", CultureInfo.InvariantCulture);
                    ouput.Code     = com.Code;
                    ouput.KeyUser  = _appService.AbpSession.UserId.ToString();
                    ouput.NgaySinh = DateTime.Today;
                    ouput.IdCty    = IdCty();
                    if (ModelState.IsValid)
                    {
                        _nccService.Update(ouput);
                    }

                    tt = "Cập Nhật Thành Công";
                }
            }

            return(Json(tt));
        }