コード例 #1
0
ファイル: InvoiceService.cs プロジェクト: abkdev0501/abk-ac
        public async Task <int> AddUpdateInvoiceEntry(int CompanyId, InvoiceEntry invoiceEntry)
        {
            InvoiceDetail invoiceDetail = new InvoiceDetail();

            if (invoiceEntry.InvoiceParticularId > 0)
            {
                var existingParticular = await _dbContext.InvoiceParticulars.Where(_ =>
                                                                                   _.Id == invoiceEntry.InvoiceParticularId).FirstOrDefaultAsync();

                existingParticular.Amount      = invoiceEntry.Amount;
                existingParticular.year        = invoiceEntry.Year;
                existingParticular.CreatedDate = invoiceEntry.CreatedDate ?? DateTime.Now;
                existingParticular.UpdatedDate = DateTime.Now;
            }
            else
            {
                if (invoiceEntry.InvoiceId > 0)
                {
                    invoiceDetail = await _dbContext.InvoiceDetails.Where(_ => _.Id == invoiceEntry.InvoiceId).FirstOrDefaultAsync();

                    invoiceDetail.Remarks = invoiceEntry.Remarks;
                }
                else
                {
                    invoiceDetail.ClientId       = invoiceEntry.ClientId;
                    invoiceDetail.CompanyId      = invoiceEntry.CompanyId;
                    invoiceDetail.Invoice_Number = GenerateInvoiceNumber((int)invoiceDetail.CompanyId, invoiceEntry.InvoiceDate);
                    invoiceDetail.UpdatedDate    = DateTime.Now;
                    invoiceDetail.CreatedDate    = DateTime.Now;
                    invoiceDetail.InvoiceDate    = invoiceEntry.InvoiceDate;
                    invoiceDetail.CreatedBy      = Convert.ToInt32(SessionHelper.UserId);
                    invoiceDetail.Remarks        = invoiceEntry.Remarks;
                    _dbContext.InvoiceDetails.Add(invoiceDetail);
                    await _dbContext.SaveChangesAsync();
                }

                InvoiceParticular invoiceParticular = new InvoiceParticular();
                invoiceParticular.Amount       = invoiceEntry.Amount;
                invoiceParticular.year         = invoiceEntry.Year;
                invoiceParticular.CreatedDate  = DateTime.Now;
                invoiceParticular.UpdatedDate  = DateTime.Now;
                invoiceParticular.InvoiceId    = invoiceDetail.Id;
                invoiceParticular.ParticularId = invoiceEntry.ParticularId;
                invoiceParticular.CreatedBy    = Convert.ToInt32(SessionHelper.UserId);

                _dbContext.InvoiceParticulars.Add(invoiceParticular);
            }
            await _dbContext.SaveChangesAsync();

            return(Convert.ToInt32(invoiceDetail.Id));
        }
コード例 #2
0
        public async Task <int> SaveDocument(DocumentMasterDto document)
        {
            DocumentMaster documentMaster = new DocumentMaster();

            try
            {
                // Add document into database
                if (document.DocumentId == 0)
                {
                    documentMaster.Name         = document.Name;
                    documentMaster.DocumentType = (int)document.DocumentType;
                    documentMaster.ClientId     = document.ClientId;
                    documentMaster.CreatedOn    = DateTime.Now;
                    documentMaster.CreatedBy    = Convert.ToInt32(SessionHelper.UserId);
                    documentMaster.Status       = (int)document.Status;
                    documentMaster.FileName     = document.FileName;
                    documentMaster.IsActive     = document.IsActive;
                    _dbContext.DocumentMasters.Add(documentMaster);
                }
                if (document.DocumentId > 0)
                {
                    documentMaster              = _dbContext.DocumentMasters.Where(_ => _.DocumentId == document.DocumentId).FirstOrDefault();
                    documentMaster.Name         = document.Name;
                    documentMaster.DocumentType = (int)document.DocumentType;
                    documentMaster.ClientId     = document.ClientId;
                    documentMaster.ModifiedOn   = DateTime.Now;
                    documentMaster.ModifiedBy   = Convert.ToInt32(SessionHelper.UserId);
                    documentMaster.Status       = (int)document.Status;
                    if (document.FileName != null)
                    {
                        documentMaster.FileName = document.FileName;
                    }
                    documentMaster.IsActive = document.IsActive;
                }
                await _dbContext.SaveChangesAsync();
            }
            catch
            {
            }
            return(documentMaster.DocumentId);
        }
コード例 #3
0
ファイル: AccountService.cs プロジェクト: abkdev0501/abk-ac
        public async Task AddUpadate(UsersDto user)
        {
            if (user.Id > 0)
            {
                var existingUser = await _dbContext.Users.FirstOrDefaultAsync(_ => _.Id == user.Id);

                existingUser.FullName     = user.FullName;
                existingUser.Address      = user.Address;
                existingUser.City         = user.City;
                existingUser.PhoneNumber  = user.PhoneNumber;
                existingUser.Pincode      = user.Pincode;
                existingUser.UpdatedDated = DateTime.Now;
                existingUser.UserTypeId   = user.UserTypeId;
                existingUser.Email        = user.Email;
                existingUser.Active       = user.Active;
                existingUser.Password     = Functions.Encrypt(user.Password);

                if (existingUser.Username != user.Username)
                {
                    var isSameUserExist = await _dbContext.Users.FirstOrDefaultAsync(_ => _.Username == user.Username);

                    if (isSameUserExist != null)
                    {
                        throw new Exception();
                    }
                }

                if (existingUser.UserTypeId != user.UserTypeId)
                {
                    _dbContext.User_Role.RemoveRange(_dbContext.User_Role.Where(_ => _.UserId == user.Id));
                    await _dbContext.SaveChangesAsync();

                    _dbContext.User_Role.Add(new User_Role
                    {
                        CreatedDate = DateTime.Now,
                        RoleId      = user.UserTypeId,
                        UserId      = user.Id,
                        UpdatedDate = DateTime.Now
                    });
                    await _dbContext.SaveChangesAsync();
                }

                if (user.CompanyIds?.Count() > 0)
                {
                    _dbContext.Company_Client_Mapping.RemoveRange(_dbContext.Company_Client_Mapping.Where(_ => _.UserId == user.Id));
                    await _dbContext.SaveChangesAsync();

                    foreach (var companyid in user.CompanyIds)
                    {
                        _dbContext.Company_Client_Mapping.Add(new Company_Client_Mapping
                        {
                            UserId    = Convert.ToInt32(existingUser.Id),
                            CompanyId = companyid
                        });
                    }
                }
            }
            else
            {
                var isSameUserExist = await _dbContext.Users.FirstOrDefaultAsync(_ => _.Username == user.Username);

                if (isSameUserExist != null)
                {
                    throw new Exception();
                }

                var userModel = new User();
                userModel.FullName     = user.FullName;
                userModel.Address      = user.Address;
                userModel.City         = user.City;
                userModel.PhoneNumber  = user.PhoneNumber;
                userModel.Pincode      = user.Pincode;
                userModel.UpdatedDated = DateTime.Now;
                userModel.Username     = user.Username;
                userModel.Password     = Functions.Encrypt(user.Password);
                userModel.CreatedDate  = DateTime.Now;
                userModel.UserTypeId   = user.UserTypeId;
                userModel.Email        = user.Email;
                userModel.Active       = user.Active;
                userModel.CreatedBy    = Convert.ToInt32(SessionHelper.UserTypeId);
                _dbContext.Users.Add(userModel);
                await _dbContext.SaveChangesAsync();

                _dbContext.User_Role.Add(new User_Role
                {
                    CreatedDate = DateTime.Now,
                    RoleId      = user.UserTypeId,
                    UserId      = userModel.Id,
                    UpdatedDate = DateTime.Now
                });

                if (user.CompanyIds?.Count() > 0)
                {
                    foreach (var companyid in user.CompanyIds)
                    {
                        _dbContext.Company_Client_Mapping.Add(new Company_Client_Mapping
                        {
                            UserId    = Convert.ToInt32(userModel.Id),
                            CompanyId = companyid
                        });
                    }
                }
            }
            await _dbContext.SaveChangesAsync();
        }
コード例 #4
0
        public async Task AddUpdateTask(TaskDTO task)
        {
            if (task.TaskId > 0)
            {
                var existingTask = await _dbContext.Tasks.FirstOrDefaultAsync(_ => _.Id == task.TaskId);

                existingTask.Name         = task.TaskName;
                existingTask.Active       = task.Active;
                existingTask.Status       = task.StatusId;
                existingTask.Description  = task.Description;
                existingTask.ClientId     = task.ClientId;
                existingTask.Priorities   = task.Priorities;
                existingTask.Remarks      = task.Remarks;
                existingTask.IsChargeble  = task.IsChargeble;
                existingTask.CompletedOn  = task.CompletedOn;
                existingTask.ModifiedOn   = DateTime.Now;
                existingTask.ChargeAmount = task.ChargeAmount;


                var existingUserTask = await _dbContext.UserTasks.FirstOrDefaultAsync(_ => _.Id == task.TaskUserId);

                existingUserTask.Status     = task.StatusId;
                existingUserTask.Comment    = task.UserComment;
                existingUserTask.UserId     = task.UserId;
                existingUserTask.ModifiedOn = DateTime.Now;
                existingUserTask.DueDate    = task.DueDate;

                if (task.IsChargeble && existingUserTask.Active != task.Active && task.Active)
                {
                    await CreateInvoice(task);
                }

                await _dbContext.SaveChangesAsync();
            }
            else
            {
                var taskDetail = new Tasks();
                taskDetail.CreatedBy    = Convert.ToInt32(SessionHelper.UserTypeId);
                taskDetail.AddedBy      = Convert.ToInt32(SessionHelper.UserId);
                taskDetail.Name         = task.TaskName;
                taskDetail.Description  = task.Description;
                taskDetail.Status       = task.StatusId;
                taskDetail.Active       = task.Active;
                taskDetail.CreatedOn    = DateTime.Now;
                taskDetail.ClientId     = task.ClientId;
                taskDetail.Priorities   = task.Priorities;
                taskDetail.Remarks      = task.Remarks;
                taskDetail.IsChargeble  = task.IsChargeble;
                taskDetail.CompletedOn  = task.CompletedOn;
                taskDetail.ChargeAmount = task.ChargeAmount;
                _dbContext.Tasks.Add(taskDetail);
                await _dbContext.SaveChangesAsync();

                _dbContext.UserTasks.Add(new UserTask
                {
                    Active    = task.Active,
                    Comment   = task.UserComment,
                    TaskId    = taskDetail.Id,
                    UserId    = task.UserId,
                    Status    = task.StatusId,
                    DueDate   = task.DueDate,
                    CreatedOn = DateTime.Now,
                    CreatedBy = Convert.ToInt32(SessionHelper.UserTypeId),
                    AddedBy   = Convert.ToInt32(SessionHelper.UserId)
                });
                await _dbContext.SaveChangesAsync();

                if (task.IsChargeble && task.Active)
                {
                    await CreateInvoice(task);
                }
            }
        }
コード例 #5
0
        public async Task AddUpdateReceiptEntry(ReceiptDto receiptEntry)
        {
            long ReceiptId = 0;

            if (receiptEntry.ReceiptId > 0)
            {
                var exitingReceipt = await _dbContext.RecieptDetails.FirstOrDefaultAsync(_ => _.Id == receiptEntry.ReceiptId);

                exitingReceipt.Status      = receiptEntry.Status;
                exitingReceipt.TotalAmount = receiptEntry.InvoiceIds?.Count() == 0 ? receiptEntry.TotalAmount : await _invoiceService.GetInvoiceAmountTotal(receiptEntry.InvoiceIds);

                exitingReceipt.UpdatedDate  = DateTime.Now;
                exitingReceipt.Discount     = receiptEntry.Discount;
                exitingReceipt.ChequeNumber = receiptEntry.ChequeNumber;
                exitingReceipt.BankName     = receiptEntry.BankName;
                exitingReceipt.Remarks      = receiptEntry.Remarks;
                exitingReceipt.companyId    = receiptEntry.CompanyId;
                exitingReceipt.clientId     = receiptEntry.ClientId;

                _dbContext.InvoiceReciepts.RemoveRange(await _dbContext.InvoiceReciepts.Where(_ => _.RecieptId == exitingReceipt.Id).ToListAsync());
                await _dbContext.SaveChangesAsync();

                ReceiptId = exitingReceipt.Id;
            }
            else
            {
                var receiptDetail = new RecieptDetail
                {
                    RecieptNo    = GenerateNextRecieptNumber(Convert.ToInt32(receiptEntry.CompanyId), receiptEntry.RecieptDate, receiptEntry.InvoiceIds),
                    Status       = receiptEntry.Status,
                    TotalAmount  = (receiptEntry.InvoiceIds == null || receiptEntry.InvoiceIds?.Count() == 0) ? receiptEntry.TotalAmount : await _invoiceService.GetInvoiceAmountTotal(receiptEntry.InvoiceIds),
                    UpdatedDate  = DateTime.Now,
                    CreatedDate  = DateTime.Now,
                    Discount     = receiptEntry.Discount,
                    ChequeNumber = receiptEntry.ChequeNumber,
                    BankName     = receiptEntry.BankName,
                    CreatedBy    = Convert.ToInt32(SessionHelper.UserTypeId),
                    AddedBy      = Convert.ToInt32(SessionHelper.UserId),
                    RecieptDate  = receiptEntry.RecieptDate,
                    Remarks      = receiptEntry.Remarks,
                    companyId    = receiptEntry.CompanyId,
                    clientId     = receiptEntry.ClientId
                };
                _dbContext.RecieptDetails.Add(receiptDetail);
                await _dbContext.SaveChangesAsync();

                ReceiptId = receiptDetail.Id;
            }

            if (receiptEntry.InvoiceIds != null && receiptEntry.InvoiceIds.Any())
            {
                foreach (var invoiceId in receiptEntry.InvoiceIds)
                {
                    _dbContext.InvoiceReciepts.Add(new InvoiceReciept
                    {
                        RecieptId = ReceiptId,
                        InvoiceId = invoiceId
                    });
                }
            }
            await _dbContext.SaveChangesAsync();
        }
コード例 #6
0
ファイル: MasterService.cs プロジェクト: abkdev0501/abk-ac
        /// <summary>
        /// Add update company
        /// </summary>
        /// <param name="data"></param>
        /// <returns></returns>
        public async Task AddUpdateCompany(CompanyDto data)
        {
            if (data.Id > 0)
            {
                var companyDetails = await _dbContext.Company_master.FirstOrDefaultAsync(_ => _.Id == data.Id);

                companyDetails.IsActive      = data.IsActive;
                companyDetails.CompanyName   = data.CompanyName;
                companyDetails.Address       = data.Address;
                companyDetails.PreferedColor = data.PreferedColor;
                companyDetails.Prefix        = data.Prefix;
                companyDetails.Type          = data.Type;
            }
            else
            {
                _dbContext.Company_master.Add(new Data.Entity.Company_master
                {
                    IsActive      = data.IsActive,
                    CompanyName   = data.CompanyName,
                    Address       = data.Address,
                    PreferedColor = data.PreferedColor,
                    Prefix        = data.Prefix,
                    Type          = data.Type
                });
            }
            await _dbContext.SaveChangesAsync();
        }