Exemplo n.º 1
0
        public async Task <string> InsertAsync(FiscalYearDto dto)
        {
            var currentFiscalYear = await GetCurrentFiscalYearAsync();

            var    con         = _baseInterface.GetConnection();
            var    transaction = con.BeginTransaction();
            string message     = "";

            try
            {
                if (dto.IsCurrent)
                {
                    _fiscalYearRepository.MakeIsCurrentFalse(con, transaction);
                }
                else
                {
                    if (currentFiscalYear is null)
                    {
                        dto.IsCurrent = true;
                    }
                }

                dto.StartDateAD = Convert.ToDateTime(_dateService.ConvertToEnglishDate(dto.StartDateBS));
                dto.EndDateAD   = Convert.ToDateTime(_dateService.ConvertToEnglishDate(dto.EndDateBS));
                int result = _fiscalYearRepository.Insert(dto.ToEntity(), transaction, con);
                message = _messageClass.ShowSuccessMessage(result);
                transaction.Commit();
            }
            catch (SqlException ex)
            {
                message = _messageClass.ShowErrorMessage(string.Format("{0} ~ {1}", ex.Number.ToString(), ex.Message));
                transaction.Rollback();
            }
            return(message);
        }
Exemplo n.º 2
0
        public async Task <string> InsertProductPrice(ProductPriceDto dto)
        {
            var    con         = _baseInterface.GetConnection();
            var    transaction = con.BeginTransaction();
            string message     = "";

            try
            {
                var product = await GetProductById(dto.ProductId);

                if (product is null)
                {
                    return(null);
                }

                _productRepository.UpdatePriceByUnitIdProductId(dto.UnitId, dto.ProductId, con, transaction);

                int result = _productRepository.InsertProductPrice(dto.ToEntity());
                message = _messageClass.ShowSuccessMessage(product.ProductId);
                transaction.Commit();
            }
            catch (SqlException ex)
            {
                message = _messageClass.ShowErrorMessage(string.Format("{0} ~ {1}", ex.Number.ToString(), ex.Message));
                transaction.Rollback();
            }
            return(message);
        }
Exemplo n.º 3
0
        public string Insert(StaffsDto dto)
        {
            var    conn        = _baseInterface.GetConnection();
            var    transaction = conn.BeginTransaction();
            string message     = "";

            try
            {
                var photoStorage = new PhotoStorages();
                photoStorage.Photo         = null;
                photoStorage.PhotoLocation = null;
                int photoStorageId = _photoStorageRepository.Insert(photoStorage, transaction, conn);

                var user = dto.ToUserEntity();
                user.PhotoStorageId = photoStorageId;
                user.Password       = Web.Repositories.Utitlities.Security.GetMd5Sum(dto.Password);
                user.CreatedDate    = DateTime.Now;
                user.CreatedBy      = Convert.ToInt32(HttpContext.Current.Session["UserId"]);
                int userId = _usersRepository.Insert(user, transaction, conn);

                var staff = dto.ToEntity();
                staff.UserId = userId;
                int staffId = _staffsRepository.Insert(staff, transaction, conn);

                message = _messageClass.ShowSuccessMessage(staffId);
                transaction.Commit();
            }
            catch (SqlException ex)
            {
                message = _messageClass.ShowErrorMessage(string.Format("{0} ~ {1}", ex.Number.ToString(), ex.Message));
                transaction.Rollback();
            }
            return(message);
        }