Пример #1
0
        public HttpResponseMessage updateBranch(Models.MstUserBranch userBranch)
        {
            try
            {
                var users = from d in db.MstUsers where d.UserId == User.Identity.GetUserId() select d;
                if (users.Any())
                {
                    var branches = from d in db.MstBranches
                                   where d.Id == userBranch.BranchId
                                   select d;

                    if (branches.Any())
                    {
                        var updateUserBranch = users.FirstOrDefault();
                        updateUserBranch.CompanyId = branches.FirstOrDefault().CompanyId;
                        updateUserBranch.BranchId  = branches.FirstOrDefault().Id;
                        db.SubmitChanges();

                        return(Request.CreateResponse(HttpStatusCode.OK));
                    }
                    else
                    {
                        return(Request.CreateResponse(HttpStatusCode.NotFound));
                    }
                }
                else
                {
                    return(Request.CreateResponse(HttpStatusCode.NotFound));
                }
            }
            catch
            {
                return(Request.CreateResponse(HttpStatusCode.InternalServerError));
            }
        }
Пример #2
0
        public Int32 insertAccountCategory(Models.MstAccountCategory accountCategory)
        {
            try
            {
                var userId = (from d in db.MstUsers where d.UserId == User.Identity.GetUserId() select d.Id).SingleOrDefault();

                Data.MstAccountCategory newAccountCategory = new Data.MstAccountCategory();
                newAccountCategory.AccountCategoryCode = accountCategory.AccountCategoryCode;
                newAccountCategory.AccountCategory     = accountCategory.AccountCategory;
                newAccountCategory.IsLocked            = accountCategory.IsLocked;
                newAccountCategory.CreatedById         = userId;
                newAccountCategory.CreatedDateTime     = DateTime.Now;
                newAccountCategory.UpdatedById         = userId;
                newAccountCategory.UpdatedDateTime     = DateTime.Now;

                db.MstAccountCategories.InsertOnSubmit(newAccountCategory);
                db.SubmitChanges();

                return(newAccountCategory.Id);
            }
            catch
            {
                return(0);
            }
        }
        public Int32 insertJournalVoucherLine(Models.TrnJournalVoucherLine journalVoucherLine)
        {
            try
            {
                Data.TrnJournalVoucherLine newJournalVoucherLine = new Data.TrnJournalVoucherLine();
                newJournalVoucherLine.JVId         = journalVoucherLine.JVId;
                newJournalVoucherLine.BranchId     = journalVoucherLine.BranchId;
                newJournalVoucherLine.AccountId    = journalVoucherLine.AccountId;
                newJournalVoucherLine.ArticleId    = journalVoucherLine.ArticleId;
                newJournalVoucherLine.Particulars  = journalVoucherLine.Particulars;
                newJournalVoucherLine.DebitAmount  = journalVoucherLine.DebitAmount;
                newJournalVoucherLine.CreditAmount = journalVoucherLine.CreditAmount;
                newJournalVoucherLine.APRRId       = journalVoucherLine.APRRId;
                newJournalVoucherLine.ARSIId       = journalVoucherLine.ARSIId;
                newJournalVoucherLine.IsClear      = journalVoucherLine.IsClear;

                db.TrnJournalVoucherLines.InsertOnSubmit(newJournalVoucherLine);
                db.SubmitChanges();

                return(newJournalVoucherLine.Id);
            }
            catch
            {
                return(0);
            }
        }
Пример #4
0
        public Int32 insertDiscount(Models.MstDiscount discount)
        {
            try
            {
                var userId = (from d in db.MstUsers where d.UserId == User.Identity.GetUserId() select d.Id).SingleOrDefault();

                Data.MstDiscount newDiscount = new Data.MstDiscount();
                newDiscount.Discount        = discount.Discount;
                newDiscount.DiscountRate    = discount.DiscountRate;
                newDiscount.IsInclusive     = discount.IsInclusive;
                newDiscount.AccountId       = discount.AccountId;
                newDiscount.IsLocked        = discount.IsLocked;
                newDiscount.CreatedById     = userId;
                newDiscount.CreatedDateTime = DateTime.Now;
                newDiscount.UpdatedById     = userId;
                newDiscount.UpdatedDateTime = DateTime.Now;
                db.MstDiscounts.InsertOnSubmit(newDiscount);
                db.SubmitChanges();

                return(newDiscount.Id);
            }
            catch
            {
                return(0);
            }
        }
        public Int32 insertTaxType(Models.MstTaxType taxType)
        {
            try
            {
                var userId = (from d in db.MstUsers where d.UserId == User.Identity.GetUserId() select d.Id).SingleOrDefault();

                Data.MstTaxType newTaxType = new Data.MstTaxType();
                newTaxType.TaxType         = taxType.TaxType;
                newTaxType.TaxRate         = taxType.TaxRate;
                newTaxType.IsInclusive     = taxType.IsInclusive;
                newTaxType.AccountId       = taxType.AccountId;
                newTaxType.IsLocked        = taxType.IsLocked;
                newTaxType.CreatedById     = userId;
                newTaxType.CreatedDateTime = DateTime.Now;
                newTaxType.UpdatedById     = userId;
                newTaxType.UpdatedDateTime = DateTime.Now;

                db.MstTaxTypes.InsertOnSubmit(newTaxType);
                db.SubmitChanges();

                return(newTaxType.Id);
            }
            catch
            {
                return(0);
            }
        }
Пример #6
0
        public Int32 insertAccountCashFlow(Models.MstAccountCashFlow accountCashFlow)
        {
            try
            {
                var userId = (from d in db.MstUsers where d.UserId == User.Identity.GetUserId() select d.Id).SingleOrDefault();

                Data.MstAccountCashFlow newAccountCashFlow = new Data.MstAccountCashFlow();
                newAccountCashFlow.AccountCashFlowCode = accountCashFlow.AccountCashFlowCode;
                newAccountCashFlow.AccountCashFlow     = accountCashFlow.AccountCashFlow;
                newAccountCashFlow.IsLocked            = accountCashFlow.IsLocked;
                newAccountCashFlow.CreatedById         = userId;
                newAccountCashFlow.CreatedDateTime     = DateTime.Now;
                newAccountCashFlow.UpdatedById         = userId;
                newAccountCashFlow.UpdatedDateTime     = DateTime.Now;

                db.MstAccountCashFlows.InsertOnSubmit(newAccountCashFlow);
                db.SubmitChanges();

                return(newAccountCashFlow.Id);
            }
            catch
            {
                return(0);
            }
        }
        public Int32 insertAccountType(Models.MstAccountType accountType)
        {
            try
            {
                var userId = (from d in db.MstUsers where d.UserId == User.Identity.GetUserId() select d.Id).SingleOrDefault();

                Data.MstAccountType newAccountType = new Data.MstAccountType();
                newAccountType.AccountTypeCode        = accountType.AccountTypeCode;
                newAccountType.AccountType            = accountType.AccountType;
                newAccountType.AccountCategoryId      = accountType.AccountCategoryId;
                newAccountType.SubCategoryDescription = accountType.SubCategoryDescription;
                newAccountType.IsLocked        = accountType.IsLocked;
                newAccountType.CreatedById     = userId;
                newAccountType.CreatedDateTime = DateTime.Now;
                newAccountType.UpdatedById     = userId;
                newAccountType.UpdatedDateTime = DateTime.Now;

                db.MstAccountTypes.InsertOnSubmit(newAccountType);
                db.SubmitChanges();

                return(newAccountType.Id);
            }
            catch
            {
                return(0);
            }
        }
Пример #8
0
        public Int32 insertTerm(Models.MstTerm term)
        {
            try
            {
                var userId = (from d in db.MstUsers where d.UserId == User.Identity.GetUserId() select d.Id).SingleOrDefault();

                Data.MstTerm newTerm = new Data.MstTerm();
                newTerm.Term            = term.Term;
                newTerm.NumberOfDays    = term.NumberOfDays;
                newTerm.IsLocked        = term.IsLocked;
                newTerm.CreatedById     = userId;
                newTerm.CreatedDateTime = DateTime.Now;
                newTerm.UpdatedById     = userId;
                newTerm.UpdatedDateTime = DateTime.Now;

                db.MstTerms.InsertOnSubmit(newTerm);
                db.SubmitChanges();

                return(newTerm.Id);
            }
            catch
            {
                return(0);
            }
        }
        public Int32 insertArticleGroup(Models.MstArticleGroup articleGroup)
        {
            try
            {
                var userId = (from d in db.MstUsers where d.UserId == User.Identity.GetUserId() select d.Id).SingleOrDefault();

                Data.MstArticleGroup newArticleGroup = new Data.MstArticleGroup();
                newArticleGroup.ArticleGroup     = articleGroup.ArticleGroup;
                newArticleGroup.ArticleTypeId    = articleGroup.ArticleTypeId;
                newArticleGroup.AccountId        = articleGroup.AccountId;
                newArticleGroup.SalesAccountId   = articleGroup.SalesAccountId;
                newArticleGroup.CostAccountId    = articleGroup.CostAccountId;
                newArticleGroup.AssetAccountId   = articleGroup.AssetAccountId;
                newArticleGroup.ExpenseAccountId = articleGroup.ExpenseAccountId;
                newArticleGroup.IsLocked         = articleGroup.IsLocked;
                newArticleGroup.CreatedById      = userId;
                newArticleGroup.CreatedDateTime  = DateTime.Now;
                newArticleGroup.UpdatedById      = userId;
                newArticleGroup.UpdatedDateTime  = DateTime.Now;

                db.MstArticleGroups.InsertOnSubmit(newArticleGroup);
                db.SubmitChanges();

                return(newArticleGroup.Id);
            }
            catch
            {
                return(0);
            }
        }
Пример #10
0
        public Int32 insertCompany(Models.MstCompany company)
        {
            try
            {
                var userId = (from d in db.MstUsers where d.UserId == User.Identity.GetUserId() select d.Id).SingleOrDefault();

                Data.MstCompany newCompany = new Data.MstCompany();
                newCompany.Company         = "NA";
                newCompany.Address         = "NA";
                newCompany.ContactNumber   = "NA";
                newCompany.TaxNumber       = "NA";
                newCompany.IsLocked        = false;
                newCompany.CreatedById     = userId;
                newCompany.CreatedDateTime = DateTime.Now;
                newCompany.UpdatedById     = userId;
                newCompany.UpdatedDateTime = DateTime.Now;

                db.MstCompanies.InsertOnSubmit(newCompany);
                db.SubmitChanges();

                return(newCompany.Id);
            }
            catch
            {
                return(0);
            }
        }
Пример #11
0
        public HttpResponseMessage AddUnit(Entities.MstUnit objUnit)
        {
            try
            {
                var currentUser = from d in db.MstUsers
                                  where d.UserId == User.Identity.GetUserId()
                                  select d;

                if (currentUser.Any())
                {
                    var currentUserId = currentUser.FirstOrDefault().Id;

                    var userForms = from d in db.MstUserForms
                                    where d.UserId == currentUserId &&
                                    d.SysForm.FormName.Equals("SystemTables")
                                    select d;

                    if (userForms.Any())
                    {
                        if (userForms.FirstOrDefault().CanAdd)
                        {
                            Data.MstUnit newUnit = new Data.MstUnit
                            {
                                Unit            = objUnit.Unit,
                                IsLocked        = true,
                                CreatedById     = currentUserId,
                                CreatedDateTime = DateTime.Now,
                                UpdatedById     = currentUserId,
                                UpdatedDateTime = DateTime.Now
                            };

                            db.MstUnits.InsertOnSubmit(newUnit);
                            db.SubmitChanges();

                            String newObject = at.GetObjectString(newUnit);
                            at.InsertAuditTrail(currentUser.FirstOrDefault().Id, GetType().Name, MethodBase.GetCurrentMethod().Name, "NA", newObject);

                            return(Request.CreateResponse(HttpStatusCode.OK, newUnit.Id));
                        }
                        else
                        {
                            return(Request.CreateResponse(HttpStatusCode.BadRequest, "Sorry. You have no rights to add unit."));
                        }
                    }
                    else
                    {
                        return(Request.CreateResponse(HttpStatusCode.BadRequest, "Sorry. You have no access for this system table page."));
                    }
                }
                else
                {
                    return(Request.CreateResponse(HttpStatusCode.BadRequest, "Theres no current user logged in."));
                }
            }
            catch (Exception e)
            {
                Debug.WriteLine(e);
                return(Request.CreateResponse(HttpStatusCode.InternalServerError, "Something's went wrong from the server."));
            }
        }
Пример #12
0
        public HttpResponseMessage AddTerm(Entities.MstTerm objTerm)
        {
            try
            {
                var currentUser = from d in db.MstUsers
                                  where d.UserId == User.Identity.GetUserId()
                                  select d;

                if (currentUser.Any())
                {
                    var currentUserId = currentUser.FirstOrDefault().Id;

                    var userForms = from d in db.MstUserForms
                                    where d.UserId == currentUserId &&
                                    d.SysForm.FormName.Equals("SystemTables")
                                    select d;

                    if (userForms.Any())
                    {
                        if (userForms.FirstOrDefault().CanAdd)
                        {
                            Data.MstTerm newTerm = new Data.MstTerm
                            {
                                Term            = objTerm.Term,
                                NumberOfDays    = objTerm.NumberOfDays,
                                IsLocked        = true,
                                CreatedById     = currentUserId,
                                CreatedDateTime = DateTime.Now,
                                UpdatedById     = currentUserId,
                                UpdatedDateTime = DateTime.Now
                            };

                            db.MstTerms.InsertOnSubmit(newTerm);
                            db.SubmitChanges();

                            return(Request.CreateResponse(HttpStatusCode.OK, newTerm.Id));
                        }
                        else
                        {
                            return(Request.CreateResponse(HttpStatusCode.BadRequest, "Sorry. You have no rights to add term."));
                        }
                    }
                    else
                    {
                        return(Request.CreateResponse(HttpStatusCode.BadRequest, "Sorry. You have no access for this system table page."));
                    }
                }
                else
                {
                    return(Request.CreateResponse(HttpStatusCode.BadRequest, "Theres no current user logged in."));
                }
            }
            catch (Exception e)
            {
                Debug.WriteLine(e);
                return(Request.CreateResponse(HttpStatusCode.InternalServerError, "Something's went wrong from the server."));
            }
        }
Пример #13
0
        public HttpResponseMessage AddAccountCategory(Entities.MstAccountCategory objAccountCategory)
        {
            try
            {
                var currentUser = from d in db.MstUsers
                                  where d.UserId == User.Identity.GetUserId()
                                  select d;

                if (currentUser.Any())
                {
                    var currentUserId = currentUser.FirstOrDefault().Id;

                    var userForms = from d in db.MstUserForms
                                    where d.UserId == currentUserId &&
                                    d.SysForm.FormName.Equals("ChartOfAccounts")
                                    select d;

                    if (userForms.Any())
                    {
                        if (userForms.FirstOrDefault().CanAdd)
                        {
                            Data.MstAccountCategory newAccountCategory = new Data.MstAccountCategory
                            {
                                AccountCategoryCode = objAccountCategory.AccountCategoryCode,
                                AccountCategory     = objAccountCategory.AccountCategory,
                                IsLocked            = true,
                                CreatedById         = currentUserId,
                                CreatedDateTime     = DateTime.Now,
                                UpdatedById         = currentUserId,
                                UpdatedDateTime     = DateTime.Now
                            };

                            db.MstAccountCategories.InsertOnSubmit(newAccountCategory);
                            db.SubmitChanges();

                            return(Request.CreateResponse(HttpStatusCode.OK));
                        }
                        else
                        {
                            return(Request.CreateResponse(HttpStatusCode.NotFound, "No rights."));
                        }
                    }
                    else
                    {
                        return(Request.CreateResponse(HttpStatusCode.NotFound, "No rights."));
                    }
                }
                else
                {
                    return(Request.CreateResponse(HttpStatusCode.BadRequest, "Theres no current user logged in."));
                }
            }
            catch (Exception e)
            {
                Debug.WriteLine(e);
                return(Request.CreateResponse(HttpStatusCode.InternalServerError, "Something's went wrong from the server."));
            }
        }
Пример #14
0
        public HttpResponseMessage AddAccountCashFlow(Entities.MstAccountCashFlow objAccountCashFlow)
        {
            try
            {
                var currentUser = from d in db.MstUsers
                                  where d.UserId == User.Identity.GetUserId()
                                  select d;

                if (currentUser.Any())
                {
                    var currentUserId = currentUser.FirstOrDefault().Id;

                    var userForms = from d in db.MstUserForms
                                    where d.UserId == currentUserId &&
                                    d.SysForm.FormName.Equals("ChartOfAccounts")
                                    select d;

                    if (userForms.Any())
                    {
                        if (userForms.FirstOrDefault().CanAdd)
                        {
                            Data.MstAccountCashFlow newAccountCashFlow = new Data.MstAccountCashFlow
                            {
                                AccountCashFlowCode = objAccountCashFlow.AccountCashFlowCode,
                                AccountCashFlow     = objAccountCashFlow.AccountCashFlow,
                                IsLocked            = objAccountCashFlow.IsLocked,
                                CreatedById         = currentUserId,
                                CreatedDateTime     = DateTime.Now,
                                UpdatedById         = currentUserId,
                                UpdatedDateTime     = DateTime.Now
                            };

                            db.MstAccountCashFlows.InsertOnSubmit(newAccountCashFlow);
                            db.SubmitChanges();

                            return(Request.CreateResponse(HttpStatusCode.OK));
                        }
                        else
                        {
                            return(Request.CreateResponse(HttpStatusCode.BadRequest, "Sorry. You have no rights to add new account cash flow in this chart of account page."));
                        }
                    }
                    else
                    {
                        return(Request.CreateResponse(HttpStatusCode.BadRequest, "Sorry. You have no access in this chart of account page."));
                    }
                }
                else
                {
                    return(Request.CreateResponse(HttpStatusCode.BadRequest, "Theres no current user logged in."));
                }
            }
            catch (Exception e)
            {
                Debug.WriteLine(e);
                return(Request.CreateResponse(HttpStatusCode.InternalServerError, "Something's went wrong from the server."));
            }
        }
Пример #15
0
        public HttpResponseMessage AddUserIPAddress(Entities.MstUserIPAddress objUserIPAddress)
        {
            try
            {
                var currentUser = from d in db.MstUsers
                                  where d.UserId == User.Identity.GetUserId()
                                  select d;

                if (currentUser.Any())
                {
                    var currentUserId = currentUser.FirstOrDefault().Id;

                    var userForms = from d in db.MstUserForms
                                    where d.UserId == currentUserId &&
                                    d.SysForm.FormName.Equals("UserDetail")
                                    select d;

                    if (userForms.Any())
                    {
                        if (userForms.FirstOrDefault().CanAdd)
                        {
                            Data.MstUserIPAddress newUserIPAddress = new Data.MstUserIPAddress
                            {
                                UserId    = objUserIPAddress.UserId,
                                IPAddress = objUserIPAddress.IPAddress,
                                Remarks   = objUserIPAddress.Remarks
                            };

                            db.MstUserIPAddresses.InsertOnSubmit(newUserIPAddress);
                            db.SubmitChanges();

                            String newObject = at.GetObjectString(newUserIPAddress);
                            at.InsertAuditTrail(currentUser.FirstOrDefault().Id, GetType().Name, MethodBase.GetCurrentMethod().Name, "NA", newObject);

                            return(Request.CreateResponse(HttpStatusCode.OK, newUserIPAddress.Id));
                        }
                        else
                        {
                            return(Request.CreateResponse(HttpStatusCode.BadRequest, "Sorry. You have no rights to add IP Address."));
                        }
                    }
                    else
                    {
                        return(Request.CreateResponse(HttpStatusCode.BadRequest, "Sorry. You have no access for this user detail page."));
                    }
                }
                else
                {
                    return(Request.CreateResponse(HttpStatusCode.BadRequest, "Theres no current user logged in."));
                }
            }
            catch (Exception e)
            {
                Debug.WriteLine(e);
                return(Request.CreateResponse(HttpStatusCode.InternalServerError, "Something's went wrong from the server."));
            }
        }
Пример #16
0
        public HttpResponseMessage insertDisbursementLineAccountsPayable(Models.TrnReceivingReceipt receivingReceipt, String CVId)
        {
            try
            {
                Data.TrnDisbursementLine newDisbursementLine = new Data.TrnDisbursementLine();

                newDisbursementLine.CVId = Convert.ToInt32(CVId);
                newDisbursementLine.BranchId = receivingReceipt.BranchId;
                newDisbursementLine.AccountId = receivingReceipt.AccountId;
                newDisbursementLine.ArticleId = receivingReceipt.SupplierId;
                newDisbursementLine.RRId = receivingReceipt.Id;
                newDisbursementLine.Particulars = receivingReceipt.DocumentReference;
                newDisbursementLine.Amount = receivingReceipt.Amount;

                db.TrnDisbursementLines.InsertOnSubmit(newDisbursementLine);
                db.SubmitChanges();

                return Request.CreateResponse(HttpStatusCode.OK);
            }
            catch (Exception e)
            {
                Debug.WriteLine(e);
                return Request.CreateResponse(HttpStatusCode.BadRequest);
            }
        }
Пример #17
0
        public Int32 insertBranch(Models.MstBranch branch)
        {
            try
            {
                var userId = (from d in db.MstUsers where d.UserId == User.Identity.GetUserId() select d.Id).SingleOrDefault();

                var codeDefault = "101";
                var lastBranch  = from d in db.MstBranches.OrderByDescending(d => d.Id) select d;
                if (lastBranch.Any())
                {
                    codeDefault = lastBranch.FirstOrDefault().BranchCode;
                    var lastBranchByCompanyId = from d in db.MstBranches.OrderByDescending(d => d.Id) where d.CompanyId == branch.CompanyId select d;
                    if (lastBranchByCompanyId.Any())
                    {
                        codeDefault = lastBranchByCompanyId.FirstOrDefault().BranchCode;
                        var CVNumber = Convert.ToInt32(lastBranchByCompanyId.FirstOrDefault().BranchCode) + 001;
                        codeDefault = zeroFill(CVNumber, 3);
                    }
                    else
                    {
                        var branchCodeIncrement = Convert.ToInt32(lastBranch.FirstOrDefault().BranchCode) + 100;
                        var branchCode          = Math.Round(Convert.ToDouble(branchCodeIncrement) / 100, 0) * 100;
                        var CVNumber            = branchCode + 001;
                        codeDefault = zeroFill(Convert.ToInt32(CVNumber), 3);
                    }
                }

                Data.MstBranch newBranch = new Data.MstBranch();
                newBranch.CompanyId       = branch.CompanyId;
                newBranch.Branch          = branch.Branch;
                newBranch.BranchCode      = codeDefault;
                newBranch.Address         = branch.Address;
                newBranch.ContactNumber   = branch.ContactNumber;
                newBranch.TaxNumber       = branch.TaxNumber;
                newBranch.IsLocked        = true;
                newBranch.CreatedById     = userId;
                newBranch.CreatedDateTime = DateTime.Now;
                newBranch.UpdatedById     = userId;
                newBranch.UpdatedDateTime = DateTime.Now;

                db.MstBranches.InsertOnSubmit(newBranch);
                db.SubmitChanges();

                return(newBranch.Id);
            }
            catch
            {
                return(0);
            }
        }
        public Int32 insertSalesInvoice(Models.TrnSalesInvoice sales)
        {
            try
            {
                var userId = (from d in db.MstUsers where d.UserId == User.Identity.GetUserId() select d.Id).SingleOrDefault();

                var lastSINumber   = from d in db.TrnSalesInvoices.OrderByDescending(d => d.Id) where d.BranchId == currentBranchId() select d;
                var SINumberResult = "0000000001";

                if (lastSINumber.Any())
                {
                    var SINumber = Convert.ToInt32(lastSINumber.FirstOrDefault().SINumber) + 0000000001;
                    SINumberResult = zeroFill(SINumber, 10);
                }

                Data.TrnSalesInvoice newSalesInvoice = new Data.TrnSalesInvoice();
                newSalesInvoice.BranchId          = currentBranchId();
                newSalesInvoice.SINumber          = SINumberResult;
                newSalesInvoice.SIDate            = DateTime.Today;
                newSalesInvoice.CustomerId        = (from d in db.MstArticles where d.ArticleTypeId == 2 select d.Id).FirstOrDefault();
                newSalesInvoice.TermId            = (from d in db.MstTerms select d.Id).FirstOrDefault();
                newSalesInvoice.DocumentReference = "NA";
                newSalesInvoice.ManualSINumber    = "NA";
                newSalesInvoice.Remarks           = "NA";
                newSalesInvoice.Amount            = 0;
                newSalesInvoice.PaidAmount        = 0;
                newSalesInvoice.AdjustmentAmount  = 0;
                newSalesInvoice.BalanceAmount     = 0;
                newSalesInvoice.SoldById          = userId;
                newSalesInvoice.PreparedById      = userId;
                newSalesInvoice.CheckedById       = userId;
                newSalesInvoice.ApprovedById      = userId;
                newSalesInvoice.IsLocked          = false;
                newSalesInvoice.CreatedById       = userId;
                newSalesInvoice.CreatedDateTime   = DateTime.Now;
                newSalesInvoice.UpdatedById       = userId;
                newSalesInvoice.UpdatedDateTime   = DateTime.Now;

                db.TrnSalesInvoices.InsertOnSubmit(newSalesInvoice);
                db.SubmitChanges();

                return(newSalesInvoice.Id);
            }
            catch (Exception e)
            {
                Debug.WriteLine(e);
                return(0);
            }
        }
        public Int32 insertReceivingReceipt(Models.TrnReceivingReceipt receivingReceipt)
        {
            try
            {
                var userId = (from d in db.MstUsers where d.UserId == User.Identity.GetUserId() select d.Id).SingleOrDefault();

                var RRNumberResult = "0000000001";

                var lastRRNumber = from d in db.TrnReceivingReceipts.OrderByDescending(d => d.Id) where d.BranchId == currentBranchId() select d;
                if (lastRRNumber.Any())
                {
                    var PONumber = Convert.ToInt32(lastRRNumber.FirstOrDefault().RRNumber) + 0000000001;
                    RRNumberResult = zeroFill(PONumber, 10);
                }

                Data.TrnReceivingReceipt newReceivingReceipt = new Data.TrnReceivingReceipt();
                newReceivingReceipt.BranchId          = currentBranchId();
                newReceivingReceipt.RRDate            = DateTime.Today;
                newReceivingReceipt.RRNumber          = RRNumberResult;
                newReceivingReceipt.SupplierId        = (from d in db.MstArticles where d.ArticleTypeId == 3 select d.Id).FirstOrDefault();
                newReceivingReceipt.TermId            = (from d in db.MstTerms select d.Id).FirstOrDefault();
                newReceivingReceipt.DocumentReference = "NA";
                newReceivingReceipt.ManualRRNumber    = "NA";
                newReceivingReceipt.Remarks           = "NA";
                newReceivingReceipt.Amount            = 0;
                newReceivingReceipt.WTaxAmount        = 0;
                newReceivingReceipt.PaidAmount        = 0;
                newReceivingReceipt.AdjustmentAmount  = 0;
                newReceivingReceipt.BalanceAmount     = 0;
                newReceivingReceipt.ReceivedById      = userId;
                newReceivingReceipt.PreparedById      = userId;
                newReceivingReceipt.CheckedById       = userId;
                newReceivingReceipt.ApprovedById      = userId;
                newReceivingReceipt.IsLocked          = false;
                newReceivingReceipt.CreatedById       = userId;
                newReceivingReceipt.CreatedDateTime   = DateTime.Now;
                newReceivingReceipt.UpdatedById       = userId;
                newReceivingReceipt.UpdatedDateTime   = DateTime.Now;

                db.TrnReceivingReceipts.InsertOnSubmit(newReceivingReceipt);
                db.SubmitChanges();

                return(newReceivingReceipt.Id);
            }
            catch
            {
                return(0);
            }
        }
        public Int32 insertStockTransferItem(Models.TrnStockTransferItem stockTransferItem)
        {
            try
            {
                Data.TrnStockTransferItem newStockTransferItem = new Data.TrnStockTransferItem();
                newStockTransferItem.STId            = stockTransferItem.STId;
                newStockTransferItem.ItemId          = stockTransferItem.ItemId;
                newStockTransferItem.ItemInventoryId = stockTransferItem.ItemInventoryId;
                newStockTransferItem.Particulars     = stockTransferItem.Particulars;
                newStockTransferItem.UnitId          = stockTransferItem.UnitId;
                newStockTransferItem.Quantity        = stockTransferItem.Quantity;
                newStockTransferItem.Cost            = stockTransferItem.Cost;
                newStockTransferItem.Amount          = stockTransferItem.Amount;
                newStockTransferItem.BaseUnitId      = stockTransferItem.BaseUnitId;

                var item = from d in db.MstArticles where d.Id == stockTransferItem.ItemId select d;
                newStockTransferItem.BaseUnitId = item.First().UnitId;

                var conversionUnit = from d in db.MstArticleUnits where d.ArticleId == stockTransferItem.ItemId && d.UnitId == stockTransferItem.UnitId select d;
                if (conversionUnit.First().Multiplier > 0)
                {
                    newStockTransferItem.BaseQuantity = stockTransferItem.Quantity * (1 / conversionUnit.First().Multiplier);
                }
                else
                {
                    newStockTransferItem.BaseQuantity = stockTransferItem.Quantity * 1;
                }

                var baseQuantity = stockTransferItem.Quantity * (1 / conversionUnit.First().Multiplier);
                if (baseQuantity > 0)
                {
                    newStockTransferItem.BaseCost = stockTransferItem.Amount / baseQuantity;
                }
                else
                {
                    newStockTransferItem.BaseCost = stockTransferItem.Amount;
                }

                db.TrnStockTransferItems.InsertOnSubmit(newStockTransferItem);
                db.SubmitChanges();

                return(newStockTransferItem.Id);
            }
            catch
            {
                return(0);
            }
        }
Пример #21
0
        // =======================
        // Update Accounts Payable
        // =======================
        public void UpdateAccountsPayable(Int32 RRId)
        {
            var receivingReceipt = from d in db.TrnReceivingReceipts where d.Id == RRId select d;

            if (receivingReceipt.Any())
            {
                Decimal paidAmount       = 0;
                Decimal adjustmentAmount = 0;

                var disbursementLines = from d in db.TrnDisbursementLines where d.RRId == RRId && d.TrnDisbursement.IsLocked == true && d.TrnDisbursement.IsCancelled == false select d;
                if (disbursementLines.Any())
                {
                    paidAmount = disbursementLines.Sum(d => d.Amount);
                }

                var journalVoucherLines = from d in db.TrnJournalVoucherLines where d.APRRId == RRId && d.TrnJournalVoucher.IsLocked == true && d.TrnJournalVoucher.IsCancelled == false select d;
                if (journalVoucherLines.Any())
                {
                    Decimal debitAmount  = journalVoucherLines.Sum(d => d.DebitAmount);
                    Decimal creditAmount = journalVoucherLines.Sum(d => d.CreditAmount);

                    adjustmentAmount = creditAmount - debitAmount;
                }

                Decimal receivingReceiptAmount = receivingReceipt.FirstOrDefault().Amount;
                Decimal balanceAmount          = (receivingReceiptAmount - paidAmount) + adjustmentAmount;

                var updateReceivingReceipt = receivingReceipt.FirstOrDefault();
                updateReceivingReceipt.PaidAmount       = paidAmount;
                updateReceivingReceipt.AdjustmentAmount = adjustmentAmount;
                updateReceivingReceipt.BalanceAmount    = balanceAmount;

                db.SubmitChanges();
            }
        }
Пример #22
0
        // ==========================
        // Update Accounts Receivable
        // ==========================
        public void UpdateAccountsReceivable(Int32 SIId)
        {
            var salesInvoice = from d in db.TrnSalesInvoices where d.Id == SIId select d;

            if (salesInvoice.Any())
            {
                Decimal paidAmount       = 0;
                Decimal adjustmentAmount = 0;

                var collectionLines = from d in db.TrnCollectionLines where d.SIId == SIId && d.TrnCollection.IsLocked == true && d.TrnCollection.IsCancelled == false select d;
                if (collectionLines.Any())
                {
                    paidAmount = collectionLines.Sum(d => d.Amount);
                }

                var journalVoucherLines = from d in db.TrnJournalVoucherLines where d.ARSIId == SIId && d.TrnJournalVoucher.IsLocked == true && d.TrnJournalVoucher.IsCancelled == false select d;
                if (journalVoucherLines.Any())
                {
                    Decimal debitAmount  = journalVoucherLines.Sum(d => d.DebitAmount);
                    Decimal creditAmount = journalVoucherLines.Sum(d => d.CreditAmount);

                    adjustmentAmount = debitAmount - creditAmount;
                }

                Decimal salesInvoiceAmount = salesInvoice.FirstOrDefault().Amount;
                Decimal balanceAmount      = (salesInvoiceAmount - paidAmount) + adjustmentAmount;

                var updateSalesInvoice = salesInvoice.FirstOrDefault();
                updateSalesInvoice.PaidAmount       = paidAmount;
                updateSalesInvoice.AdjustmentAmount = adjustmentAmount;
                updateSalesInvoice.BalanceAmount    = balanceAmount;

                db.SubmitChanges();
            }
        }
Пример #23
0
        // ==================
        // Insert Audit Trail
        // ==================
        public void InsertAuditTrail(Int32 UserId, String Entity, String Activity, String OldObject, String NewObject)
        {
            try
            {
                var currentUser = from d in db.MstUsers where d.Id == UserId select d;
                if (currentUser.Any())
                {
                    if (currentUser.FirstOrDefault().ActivateAuditTrail)
                    {
                        Data.SysAuditTrail newAuditTrail = new Data.SysAuditTrail
                        {
                            AuditDate = DateTime.Now,
                            UserId    = UserId,
                            Entity    = Entity,
                            Activity  = Activity,
                            OldObject = OldObject,
                            NewObject = NewObject
                        };

                        db.SysAuditTrails.InsertOnSubmit(newAuditTrail);
                        db.SubmitChanges();
                    }
                }
            }
            catch (Exception e)
            {
                Debug.WriteLine(e);
            }
        }
Пример #24
0
        public async Task <ActionResult> ChangePassword(ChangePasswordViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }
            var result = await UserManager.ChangePasswordAsync(User.Identity.GetUserId(), model.OldPassword, model.NewPassword);

            if (result.Succeeded)
            {
                Data.easyfisdbDataContext db = new Data.easyfisdbDataContext();
                var users = from d in db.MstUsers where d.UserId == User.Identity.GetUserId() select d;

                if (users.Any())
                {
                    var updateUser = users.FirstOrDefault();

                    updateUser.Password = model.NewPassword;

                    db.SubmitChanges();
                }

                var user = await UserManager.FindByIdAsync(User.Identity.GetUserId());

                if (user != null)
                {
                    await SignInManager.SignInAsync(user, isPersistent : false, rememberBrowser : false);
                }
                return(RedirectToAction("Index", new { Message = ManageMessageId.ChangePasswordSuccess }));
            }
            AddErrors(result);
            return(View(model));
        }
Пример #25
0
        public Int32 insertStockIn(Models.TrnStockIn stockIn)
        {
            try
            {
                var lastINNumber = from d in db.TrnStockIns.OrderByDescending(d => d.Id)
                                   where d.BranchId == currentBranchId()
                                   select d;

                var INNumberResult = "0000000001";

                if (lastINNumber.Any())
                {
                    var INNumber = Convert.ToInt32(lastINNumber.FirstOrDefault().INNumber) + 0000000001;
                    INNumberResult = zeroFill(INNumber, 10);
                }

                var users = (from d in db.MstUsers where d.UserId == User.Identity.GetUserId() select d).FirstOrDefault();

                Data.TrnStockIn newStockIn = new Data.TrnStockIn();
                newStockIn.BranchId        = currentBranchId();
                newStockIn.INNumber        = INNumberResult;
                newStockIn.INDate          = DateTime.Today;
                newStockIn.AccountId       = users.IncomeAccountId;
                newStockIn.ArticleId       = (from d in db.MstArticles where d.ArticleTypeId == 6 select d.Id).FirstOrDefault();
                newStockIn.Particulars     = "NA";
                newStockIn.ManualINNumber  = "NA";
                newStockIn.IsProduced      = false;
                newStockIn.PreparedById    = users.Id;
                newStockIn.CheckedById     = users.Id;
                newStockIn.ApprovedById    = users.Id;
                newStockIn.IsLocked        = false;
                newStockIn.CreatedById     = users.Id;
                newStockIn.CreatedDateTime = DateTime.Now;
                newStockIn.UpdatedById     = users.Id;
                newStockIn.UpdatedDateTime = DateTime.Now;

                db.TrnStockIns.InsertOnSubmit(newStockIn);
                db.SubmitChanges();

                return(newStockIn.Id);
            }
            catch (Exception e)
            {
                Debug.WriteLine(e);
                return(0);
            }
        }
Пример #26
0
        public Int32 insertStockTransfer(Models.TrnStockTransfer stockTransfer)
        {
            try
            {
                var userId = (from d in db.MstUsers where d.UserId == User.Identity.GetUserId() select d.Id).SingleOrDefault();

                var lastSTNumber   = from d in db.TrnStockTransfers.OrderByDescending(d => d.Id) where d.BranchId == currentBranchId() select d;
                var STNumberResult = "0000000001";

                if (lastSTNumber.Any())
                {
                    var STNumber = Convert.ToInt32(lastSTNumber.FirstOrDefault().STNumber) + 0000000001;
                    STNumberResult = zeroFill(STNumber, 10);
                }

                var users         = from d in db.MstUsers where d.Id == userId select d;
                var branches      = from d in db.MstBranches where d.Id != currentBranchId() && d.CompanyId == users.FirstOrDefault().CompanyId select d;
                var otherArticles = from d in db.MstArticles where d.ArticleTypeId == 6 select d;

                Data.TrnStockTransfer newStockTransfer = new Data.TrnStockTransfer();
                newStockTransfer.BranchId        = currentBranchId();
                newStockTransfer.STNumber        = STNumberResult;
                newStockTransfer.STDate          = DateTime.Today;
                newStockTransfer.ToBranchId      = branches.FirstOrDefault().Id;
                newStockTransfer.ArticleId       = otherArticles.FirstOrDefault().Id;
                newStockTransfer.Particulars     = "NA";
                newStockTransfer.ManualSTNumber  = "NA";
                newStockTransfer.PreparedById    = userId;
                newStockTransfer.CheckedById     = userId;
                newStockTransfer.ApprovedById    = userId;
                newStockTransfer.IsLocked        = false;
                newStockTransfer.CreatedById     = userId;
                newStockTransfer.CreatedDateTime = DateTime.Now;
                newStockTransfer.UpdatedById     = userId;
                newStockTransfer.UpdatedDateTime = DateTime.Now;

                db.TrnStockTransfers.InsertOnSubmit(newStockTransfer);
                db.SubmitChanges();

                return(newStockTransfer.Id);
            }
            catch
            {
                return(0);
            }
        }
Пример #27
0
        public Int32 insertStockOut(Models.TrnStockOut stockOut)
        {
            try
            {
                var lastOTNumber = from d in db.TrnStockOuts.OrderByDescending(d => d.Id)
                                   where d.BranchId == currentBranchId()
                                   select d;

                var OTNumberResult = "0000000001";

                if (lastOTNumber.Any())
                {
                    var OTNumber = Convert.ToInt32(lastOTNumber.FirstOrDefault().OTNumber) + 0000000001;
                    OTNumberResult = zeroFill(OTNumber, 10);
                }

                var users = (from d in db.MstUsers where d.UserId == User.Identity.GetUserId() select d).FirstOrDefault();

                Data.TrnStockOut newStockOut = new Data.TrnStockOut();
                newStockOut.BranchId        = currentBranchId();
                newStockOut.OTNumber        = OTNumberResult;
                newStockOut.OTDate          = DateTime.Today;
                newStockOut.AccountId       = users.IncomeAccountId;
                newStockOut.ArticleId       = (from d in db.MstArticles where d.ArticleTypeId == 6 select d.Id).FirstOrDefault();
                newStockOut.Particulars     = "NA";
                newStockOut.ManualOTNumber  = "NA";
                newStockOut.PreparedById    = users.Id;
                newStockOut.CheckedById     = users.Id;
                newStockOut.ApprovedById    = users.Id;
                newStockOut.IsLocked        = false;
                newStockOut.CreatedById     = users.Id;
                newStockOut.CreatedDateTime = DateTime.Now;
                newStockOut.UpdatedById     = users.Id;
                newStockOut.UpdatedDateTime = DateTime.Now;

                db.TrnStockOuts.InsertOnSubmit(newStockOut);
                db.SubmitChanges();

                return(newStockOut.Id);
            }
            catch
            {
                return(0);
            }
        }
Пример #28
0
        public Int32 insertPurchaseOrder(Models.TrnPurchaseOrder purchaseOrder)
        {
            try
            {
                var userId = (from d in db.MstUsers where d.UserId == User.Identity.GetUserId() select d.Id).SingleOrDefault();

                var PONumberResult = "0000000001";
                var lastPONumber   = from d in db.TrnPurchaseOrders.OrderByDescending(d => d.Id) where d.BranchId == currentBranchId() select d;
                if (lastPONumber.Any())
                {
                    var PONumber = Convert.ToInt32(lastPONumber.FirstOrDefault().PONumber) + 0000000001;
                    PONumberResult = zeroFill(PONumber, 10);
                }

                Data.TrnPurchaseOrder newPurchaseOrder = new Data.TrnPurchaseOrder();
                newPurchaseOrder.BranchId            = currentBranchId();
                newPurchaseOrder.PONumber            = PONumberResult;
                newPurchaseOrder.PODate              = DateTime.Today;
                newPurchaseOrder.SupplierId          = (from d in db.MstArticles where d.ArticleTypeId == 3 select d.Id).FirstOrDefault();
                newPurchaseOrder.TermId              = (from d in db.MstTerms select d.Id).FirstOrDefault();
                newPurchaseOrder.ManualRequestNumber = "NA";
                newPurchaseOrder.ManualPONumber      = "NA";
                newPurchaseOrder.DateNeeded          = DateTime.Today;
                newPurchaseOrder.Remarks             = "NA";
                newPurchaseOrder.IsClose             = false;
                newPurchaseOrder.RequestedById       = userId;
                newPurchaseOrder.PreparedById        = userId;
                newPurchaseOrder.CheckedById         = userId;
                newPurchaseOrder.ApprovedById        = userId;
                newPurchaseOrder.IsLocked            = false;
                newPurchaseOrder.CreatedById         = userId;
                newPurchaseOrder.CreatedDateTime     = DateTime.Now;
                newPurchaseOrder.UpdatedById         = userId;
                newPurchaseOrder.UpdatedDateTime     = DateTime.Now;

                db.TrnPurchaseOrders.InsertOnSubmit(newPurchaseOrder);
                db.SubmitChanges();

                return(newPurchaseOrder.Id);
            }
            catch
            {
                return(0);
            }
        }
Пример #29
0
        public HttpResponseMessage UpdateCurrentUserBranch(Entities.MstUserBranch objUserBranch)
        {
            try
            {
                var currentUser = from d in db.MstUsers
                                  where d.UserId == User.Identity.GetUserId()
                                  select d;

                if (currentUser.Any())
                {
                    var currentUserId = currentUser.FirstOrDefault().Id;

                    var userBranch = from d in db.MstUserBranches
                                     where d.BranchId == objUserBranch.BranchId &&
                                     d.UserId == currentUserId
                                     select d;

                    if (userBranch.Any())
                    {
                        var updateCurrentBranch = currentUser.FirstOrDefault();
                        updateCurrentBranch.CompanyId       = userBranch.FirstOrDefault().MstBranch.CompanyId;
                        updateCurrentBranch.BranchId        = userBranch.FirstOrDefault().BranchId;
                        updateCurrentBranch.UpdatedById     = currentUserId;
                        updateCurrentBranch.UpdatedDateTime = DateTime.Now;

                        db.SubmitChanges();

                        return(Request.CreateResponse(HttpStatusCode.OK));
                    }
                    else
                    {
                        return(Request.CreateResponse(HttpStatusCode.BadRequest, "Sorry. Branch you selected was not found."));
                    }
                }
                else
                {
                    return(Request.CreateResponse(HttpStatusCode.BadRequest, "Theres no current user logged in."));
                }
            }
            catch (Exception e)
            {
                Debug.WriteLine(e);
                return(Request.CreateResponse(HttpStatusCode.InternalServerError, "Something's went wrong from the server."));
            }
        }
        public HttpResponseMessage AddShopOrderLine(Entities.TrnShopOrderLine objShopOrderLine)
        {
            try
            {
                HttpStatusCode responseStatusCode = HttpStatusCode.OK;
                String         responseMessage    = "";

                var currentUser = from d in db.MstUsers where d.UserId == User.Identity.GetUserId() select d;
                var userForm    = from d in db.MstUserForms where d.UserId == currentUser.FirstOrDefault().Id&& d.SysForm.FormName.Equals("ShopOrderDetail") select d;
                var shopOrder   = from d in db.TrnShopOrders where d.Id == objShopOrderLine.SPId select d;

                if (!userForm.Any())
                {
                    responseStatusCode = HttpStatusCode.NotFound; responseMessage = "No rights.";
                }
                else if (!userForm.FirstOrDefault().CanAdd)
                {
                    responseStatusCode = HttpStatusCode.BadRequest; responseMessage = "No add rights.";
                }
                else if (shopOrder.FirstOrDefault().IsLocked)
                {
                    responseStatusCode = HttpStatusCode.BadRequest; responseMessage = "Add is not allowed if the current document is locked.";
                }
                else
                {
                    Data.TrnShopOrderLine newShopOrderLine = new Data.TrnShopOrderLine
                    {
                        SPId         = objShopOrderLine.SPId,
                        ActivityDate = Convert.ToDateTime(objShopOrderLine.ActivityDate),
                        Activity     = objShopOrderLine.Activity,
                        UserId       = currentUser.FirstOrDefault().Id
                    };

                    db.TrnShopOrderLines.InsertOnSubmit(newShopOrderLine);
                    db.SubmitChanges();
                }

                return(Request.CreateResponse(responseStatusCode, responseMessage));
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex);
                return(Request.CreateResponse(HttpStatusCode.InternalServerError, ex.Message));
            }
        }
Пример #31
0
        public async Task<ActionResult> Register(RegisterViewModel model)
        {

            var response = HttpContext.Request.Form["g-recaptcha-response"];
            string secretKey = "6LeNBiMTAAAAAMZUdKMa_Q4_XRGLjOEjpVP96fge";
            var client = new System.Net.WebClient();
            var verificationResultJson = client.DownloadString(string.Format("https://www.google.com/recaptcha/api/siteverify?secret={0}&response={1}", secretKey, response));
            var verificationResult = JsonConvert.DeserializeObject<CaptchaVerificationResult>(verificationResultJson);

            if (!verificationResult.Success)
            {
                ModelState.AddModelError("CaptiaError", "ERROR: Invalid recaptcha challenge.");
            }
            else
            {
                if (ModelState.IsValid)
                {
                    var user = new ApplicationUser
                    {
                        UserName = model.UserName,
                        FullName = model.FullName,
                    };

                    //var user = new ApplicationUser { UserName = model.Email, Email = model.Email };
                    var result = await UserManager.CreateAsync(user, model.Password);
                    if (result.Succeeded)
                    {
                        await SignInManager.SignInAsync(user, isPersistent: false, rememberBrowser: false);

                        // For more information on how to enable account confirmation and password reset please visit http://go.microsoft.com/fwlink/?LinkID=320771
                        // Send an email with this link
                        // string code = await UserManager.GenerateEmailConfirmationTokenAsync(user.Id);
                        // var callbackUrl = Url.Action("ConfirmEmail", "Account", new { userId = user.Id, code = code }, protocol: Request.Url.Scheme);
                        // await UserManager.SendEmailAsync(user.Id, "Confirm your account", "Please confirm your account by clicking <a href=\"" + callbackUrl + "\">here</a>");

                        Data.easyfisdbDataContext db = new Data.easyfisdbDataContext();

                        var company = from d in db.MstCompanies select d;
                        var branch = from d in db.MstBranches where d.CompanyId == company.FirstOrDefault().Id select d;
                        var account = from d in db.MstAccounts select d;

                        Data.MstUser newMstUser = new Data.MstUser();
                        newMstUser.UserName = model.UserName;
                        newMstUser.Password = model.Password;
                        newMstUser.FullName = model.FullName;
                        newMstUser.IsLocked = true;
                        newMstUser.CreatedById = 0;
                        newMstUser.CreatedDateTime = DateTime.Now;
                        newMstUser.UpdatedById = 0;
                        newMstUser.UpdatedDateTime = DateTime.Now;
                        newMstUser.UserId = user.Id;
                        newMstUser.CompanyId = company.FirstOrDefault().Id;
                        newMstUser.BranchId = branch.FirstOrDefault().Id;
                        newMstUser.IncomeAccountId = account.FirstOrDefault().Id;
                        newMstUser.SupplierAdvancesAccountId = account.FirstOrDefault().Id;
                        newMstUser.CustomerAdvancesAccountId = account.FirstOrDefault().Id;
                        newMstUser.OfficialReceiptName = "Official Receipt";

                        db.MstUsers.InsertOnSubmit(newMstUser);
                        db.SubmitChanges();

                        var mstUsersData = from d in db.MstUsers where d.UserId == user.Id select d;
                        if (mstUsersData.Any())
                        {
                            var mstUserId = (from d in db.MstUsers.OrderByDescending(d => d.Id) where d.UserId == user.Id select d.Id).FirstOrDefault();

                            var updateMstUsersData = mstUsersData.FirstOrDefault();
                            updateMstUsersData.CreatedById = mstUserId;
                            updateMstUsersData.UpdatedById = mstUserId;

                            db.SubmitChanges();
                        }

                        return RedirectToAction("Register", "Account");
                    }
                    //AddErrors(result);
                }
            }
            // If we got this far, something failed, redisplay form
            return View(model);
        }
Пример #32
0
        public async Task<ActionResult> ChangePassword(ChangePasswordViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return View(model);
            }
            var result = await UserManager.ChangePasswordAsync(User.Identity.GetUserId(), model.OldPassword, model.NewPassword);
            if (result.Succeeded)
            {

                Data.easyfisdbDataContext db = new Data.easyfisdbDataContext();
                var users = from d in db.MstUsers where d.UserId == User.Identity.GetUserId() select d;

                if (users.Any())
                {
                    var updateUser = users.FirstOrDefault();

                    updateUser.Password = model.NewPassword;

                    db.SubmitChanges();
                }

                var user = await UserManager.FindByIdAsync(User.Identity.GetUserId());
                if (user != null)
                {
                    await SignInManager.SignInAsync(user, isPersistent: false, rememberBrowser: false);
                }
                return RedirectToAction("Index", new { Message = ManageMessageId.ChangePasswordSuccess });
            }
            AddErrors(result);
            return View(model);
        }