Beispiel #1
0
        public void Update(SupplierGroup group)
        {
            var sqlSupplierGroup = SqlSupplierGroup.FromSupplierGroup(group);

            context.SetModified(sqlSupplierGroup);
            context.SaveChanges();
        }
Beispiel #2
0
 public void EditSupplier(
      Code code
     , Name name
     , Email email
     , Phone phone
     , SupplierGroup supplierGroup
     , PaymentTerm paymentTerm
     , GeneralText notes
     , bool isInformalSupplier
     , string rnc
     , string homeOrApartment
     , string city
     , string street
     , Country country
     , EntityStatus status)
 {
     Code                 = code;
     Name                 = name;
     Email                = email;
     Phone                = phone;
     Rnc                  = rnc;
     HomeOrApartment      = homeOrApartment;
     City                 = city;
     Street               = street;
     SupplierGroup        = supplierGroup;
     PaymentTerm          = paymentTerm;
     Notes                = notes;
     IsInformalSupplier   = isInformalSupplier;
     Country              = country;
     Status               = status;
     Modified             = DateTime.Now;
 }
        public List <Supplier> QuerySuppliersByGroupID(int _groupID)
        {
            SupplierGroup   _supGroup    = QueryByID(_groupID);
            List <Supplier> _suppliers   = new List <Supplier>();
            string          _supplierIDs = _supGroup.SupplierIDs;

            if (!string.IsNullOrEmpty(_supplierIDs))
            {
                if (!string.IsNullOrEmpty(_supplierIDs.Trim()))
                {
                    var _supidArray = _supplierIDs.Split('|');
                    foreach (var _id in _supidArray)
                    {
                        if (!string.IsNullOrEmpty(_id.Trim()))
                        {
                            try
                            {
                                Supplier _supplier = _context.Suppliers.ToList().Where(s => s.SupplierID == Convert.ToInt32(_id)).FirstOrDefault();
                                if (_supplier != null)
                                {
                                    _suppliers.Add(_supplier);
                                }
                                continue;
                            }
                            catch { }
                        }
                    }
                }
            }

            return(_suppliers);
        }
Beispiel #4
0
        public void Create(SupplierGroup group)
        {
            var sqlSupplierGroup = SqlSupplierGroup.FromSupplierGroup(group);

            context.Groups.Add(sqlSupplierGroup);
            context.SaveChanges();
        }
        public async Task <IActionResult> Edit(int id, [Bind("SupplierGroupId,Code,Name,CreateBy,CreateDate,UpdateBy,UpdateDate,IsActive,IsDelete")] SupplierGroup supplierGroup)
        {
            if (id != supplierGroup.SupplierGroupId)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(supplierGroup);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!SupplierGroupExists(supplierGroup.SupplierGroupId))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(supplierGroup));
        }
Beispiel #6
0
        public async Task <ApiResult <PagedResult <AccountsDto> > > GetAccountsPagingAsync(int pageIndex, int pageSize)
        {
            var accounts = await(from au in _context.AppUsers
                                 join emp in _context.Employees on au.Id equals emp.AppuserId
                                 into EmployeeGroup
                                 from e in EmployeeGroup.DefaultIfEmpty()
                                 join cus in _context.Customers on au.Id equals cus.AppUserId
                                 into CustomerGroup
                                 from c in CustomerGroup.DefaultIfEmpty()
                                 join sup in _context.Suppliers on au.Id equals sup.AppUserId
                                 into SupplierGroup
                                 from s in SupplierGroup.DefaultIfEmpty()
                                 select new AccountsDto()
            {
                Id           = au.Id,
                UserName     = au.UserName,
                Email        = au.Email,
                EmployeeName = e.Name,
                CustomerName = c.Name,
                SupplierName = s.Name,
                PhoneNumber  = au.PhoneNumber
            }).GetPagedAsync(pageIndex, pageSize);

            return(new ApiResult <PagedResult <AccountsDto> >(HttpStatusCode.OK, accounts));
        }
Beispiel #7
0
 public Supplier(Code code
     , Name name
     , Email email
     , Phone phone
     , string rnc
     , string homeOrApartment
     , string city
     , string street
     , Country country
     , SupplierGroup supplierGroup
     , PaymentTerm paymentTerm
     , GeneralText notes
     , bool isInformalSupplier
     , DateTime created
     , DateTime? modified = null
     , EntityStatus status = EntityStatus.Active)
 {
     Code                = code;
     Name                = name;
     Email               = email;
     Phone               = phone;
     Rnc                 = rnc;
     HomeOrApartment     = homeOrApartment;
     City                = city;
     Street              = street;
     Country             = country;
     SupplierGroup       = supplierGroup;
     PaymentTerm         = paymentTerm;
     Notes               = notes;
     IsInformalSupplier  = isInformalSupplier;
     Created             = created == DateTime.MinValue ? DateTime.Now : created;
     Modified            = modified;
     Status              = status;
 }
Beispiel #8
0
        /// <summary>Converts a relational database representation to a domain model object.</summary>
        public SupplierGroup ToSupplierGroup()
        {
            var supplierGroup = new SupplierGroup(Id, Name);

            Suppliers.ToList().ForEach(s => supplierGroup.AddSupplier(s.ToSupplier()));

            return(supplierGroup);
        }
 public static SupplierGroupViewModel FromSupplierGroup(SupplierGroup supplierGroup)
 {
     return(new SupplierGroupViewModel
     {
         Id = supplierGroup.Id,
         Name = supplierGroup.Name
     });
 }
        public SupplierGroup Add(SupplierGroup SPG, string userid)
        {
            var sqlQuery = @"INSERT INTO SUPPLIERGROUP (IDSUPPLIERGROUP, SUPPLIERGROUPNAME, INPUTBY, INPUTDATE, UPDATEBY, UPDATEDATE) VALUES
                           ('" + SPG.IDSUPPLIERGROUP + @"', '" + SPG.SUPPLIERGROUPNAME + "', " + Convert.ToInt32(userid) + ", '" + DateTime.Now + @"', " + Convert.ToInt32(userid) + ", '" + DateTime.Now + @"'); " + "SELECT CAST(SCOPE_IDENTITY() as int)";
            var SID      = _db.Query <int>(sqlQuery, SPG).Single();

            SPG.SID = SID;
            return(SPG);
        }
Beispiel #11
0
        public void FromSupplierGroup_ValidInput_ShouldReturnSqlSupplierGroupWithCopiedValues()
        {
            var group  = new SupplierGroup(supplierGroupId, supplierGroupName);
            var result = SqlSupplierGroup.FromSupplierGroup(group);

            Assert.NotNull(result);

            Assert.AreEqual(supplierGroupId, result.Id);
            Assert.AreEqual(supplierGroupName, result.Name);
        }
Beispiel #12
0
        public void AddSupplier_SupplierBelongsToDifferentGroup_ShouldAddAndUpdateSupplier()
        {
            var tempGroup = new SupplierGroup(id, "temp group");
            var supplier  = SupplierTests.CreateSupplier("*****@*****.**", tempGroup); //at this moment, supplier belongs to tempgroup - assigned in constructor

            group.AddSupplier(supplier);

            Assert.AreEqual(1, group.Suppliers.Count);
            Assert.AreEqual(group.Name, supplier.Group.Name);
        }
Beispiel #13
0
        public async Task <ApiResult <AccountDto> > GetAccountAsync(Guid userId)
        {
            var checkAccount = await _userManager.FindByIdAsync(userId.ToString(("D")));

            if (checkAccount == null)
            {
                return(new ApiResult <AccountDto>(HttpStatusCode.NotFound, $"Không tìm thấy tài khoản có mã: {userId}"));
            }
            var roles = await _userManager.GetRolesAsync(checkAccount);

            var accountRoles = new List <AccountRolesDto>();

            foreach (var r in roles)
            {
                var role = await _roleManager.FindByNameAsync(r);

                if (role != null)
                {
                    accountRoles.Add(ObjectMapper.Mapper.Map <AppRole, AccountRolesDto>(role));
                }
            }
            var accountDetail = await(from au in _context.AppUsers
                                      join emp in _context.Employees on au.Id equals emp.AppuserId
                                      into EmployeeGroup
                                      from e in EmployeeGroup.DefaultIfEmpty()
                                      join cus in _context.Customers on au.Id equals cus.AppUserId
                                      into CustomerGroup
                                      from c in CustomerGroup.DefaultIfEmpty()
                                      join sup in _context.Suppliers on au.Id equals sup.AppUserId
                                      into SupplierGroup
                                      from s in SupplierGroup.DefaultIfEmpty()
                                      where au.Id == userId
                                      select new AccountDto()
            {
                Id      = au.Id,
                Address = e.Address != null
                        ? e.Address
                        : (c.Address != null ? c.Address : (s.Address != null ? s.Address : "")),
                Email       = au.Email,
                Name        = e.Name != null ? e.Name : (c.Name != null ? c.Name : (s.Name != null ? s.Name : "")),
                PhoneNumber = au.PhoneNumber != null
                        ? au.PhoneNumber
                        : (e.PhoneNumber != null
                            ? e.PhoneNumber
                            : (c.PhoneNumber != null
                                ? c.PhoneNumber
                                : (
                                   s.PhoneNumber != null ? s.PhoneNumber : ""))),
                UserName = au.UserName,
                InRoles  = accountRoles
            }).SingleOrDefaultAsync();

            return(new ApiResult <AccountDto>(HttpStatusCode.OK, accountDetail));
        }
        public void Update_ValidGroup_ShouldUpdateGroupViaContext()
        {
            var group        = supplierGroupDal.GetOne(supplierGroupId);
            var newName      = group.Name + " - updated";
            var updatedGroup = new SupplierGroup(group.Id, newName);

            supplierGroupDal.Update(updatedGroup);

            context.Verify(c => c.SetModified(It.IsAny <object>()));
            context.Verify(c => c.SaveChanges(), Times.Once);
        }
        public async Task <IActionResult> Create([Bind("SupplierGroupId,Code,Name,CreateBy,CreateDate,UpdateBy,UpdateDate,IsActive,IsDelete")] SupplierGroup supplierGroup)
        {
            if (ModelState.IsValid)
            {
                _context.Add(supplierGroup);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(supplierGroup));
        }
        public int Delete(int _sgID)
        {
            SupplierGroup _sgObj = _context.SupplierGroups.Where(s => s.ID == _sgID && s.active == true).FirstOrDefault();

            if (_sgObj != null)
            {
                _sgObj.active = false;
                _context.SaveChanges();
                return(1);
            }
            return(-99);
        }
        public SupplierGroup Update(SupplierGroup SPG, string userid)
        {
            var sqlQuery =
                "UPDATE SUPPLIERGROUP " +
                "SET IDSUPPLIERGROUP    = '" + SPG.IDSUPPLIERGROUP + "', " +
                "    SUPPLIERGROUPNAME  = '" + SPG.SUPPLIERGROUPNAME + "', " +
                "    UPDATEBY      = '" + Convert.ToInt32(userid) + "', " +
                "    UPDATEDATE    = '" + DateTime.Now + "' " +
                "WHERE SID = " + SPG.SID + "";

            this._db.Execute(sqlQuery, SPG);
            return(SPG);
        }
Beispiel #18
0
        /// <summary>Converts a domain model object to a form that is suitable for storing in a relational database.</summary>
        public static SqlSupplierGroup FromSupplierGroup(SupplierGroup group)
        {
            if (group == null)
            {
                throw new ArgumentNullException("Supplier group can't be null.");
            }

            return(new SqlSupplierGroup
            {
                Id = group.Id,
                Name = group.Name,
                Suppliers = group.Suppliers.Select(s => SqlSupplier.FromSupplier(s)).ToList()
            });
        }
Beispiel #19
0
        public JsonResult Edit(SupplierGroup suppliergroup, string userid)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    SPG.Update(suppliergroup, Session["userid"].ToString());
                }
            }
            catch
            {
                return(Json("error"));
            }

            return(Json("success"));
        }
Beispiel #20
0
        public void FromSupplier_ValidInput_ShouldReturnSqlSupplierWithCopiedValues()
        {
            var group    = new SupplierGroup(101, "Initial supplier group");
            var supplier = SupplierTests.CreateSupplier("*****@*****.**", group);

            var result = SqlSupplier.FromSupplier(supplier);

            Assert.NotNull(result);

            Assert.AreEqual(0, result.Id);
            Assert.AreEqual("John Doe", result.Name);
            Assert.AreEqual("Vaclavske Namesti 125", result.Address);
            Assert.AreEqual("*****@*****.**", result.EmailAddress);
            Assert.AreEqual("723123456", result.PhoneNumber);
            Assert.AreEqual(101, result.GroupId);
        }
        public int Save(SupplierGroup model)
        {
            SupplierGroup _supplierGroup = _context.SupplierGroups.Where(s => s.ID == model.ID).FirstOrDefault();

            if (_supplierGroup == null)
            {
                model.MailList    = model.MailList ?? "";
                model.SupplierIDs = model.SupplierIDs ?? "";
                model.active      = true;
                _context.SupplierGroups.Add(model);
            }
            else
            {
                _supplierGroup.GroupName   = model.GroupName;
                _supplierGroup.MailList    = model.MailList ?? "";
                _supplierGroup.active      = model.active;
                _supplierGroup.SupplierIDs = model.SupplierIDs ?? "";
            }
            _context.SaveChanges();
            return(model.ID);
        }
Beispiel #22
0
        // Save Group
        public JsonResult SaveGroup(SupplierGroup model)
        {
            string Msg = null;

            SupplierGroup aGroup = new SupplierGroup();

            if (model.GroupName != null)
            {
                var groupNames = db.SupplierGroup.Where(c => c.GroupName == model.GroupName).FirstOrDefault();

                if (ModelState.IsValid)
                {
                    if (groupNames == null)
                    {
                        if (model.GroupID > 0)
                        {
                            aGroup           = db.SupplierGroup.SingleOrDefault(x => x.GroupID == model.GroupID);
                            aGroup.GroupName = model.GroupName;
                            db.SaveChanges();
                            Msg = "Update Successfully";
                        }
                        else
                        {
                            db.SupplierGroup.Add(model);
                            db.SaveChanges();
                            Msg = "Group Name Save Successfully";
                        }
                    }
                    else
                    {
                        Msg = "Group Name already Exists";
                    }
                }
            }
            else
            {
                Msg = "Null field Not Except";
            }
            return(Json(Msg, JsonRequestBehavior.AllowGet));
        }
Beispiel #23
0
        public async Task <ApiResult <PagedResult <ReceiptVouchersDto> > > GetReceiptVoucherPagingAsync(int pageIndex, int pageSize, string accountId)
        {
            var checkEmployee = await _context.Employees.Where(x => x.AppuserId.ToString() == accountId)
                                .SingleOrDefaultAsync();

            if (checkEmployee == null)
            {
                return(new ApiResult <PagedResult <ReceiptVouchersDto> >(HttpStatusCode.NotFound, $"Lỗi tài khoản đăng nhập"));
            }
            var receiptVouchers = await(from rv in _context.ReceiptVouchers
                                        join employee in _context.Employees on rv.EmployeeId equals employee.Id
                                        into EmployeeGroup
                                        from e in EmployeeGroup.DefaultIfEmpty()
                                        join customer in _context.Customers on rv.CustomerId equals customer.Id
                                        into CustomerGroup
                                        from c in CustomerGroup.DefaultIfEmpty()
                                        join supplier in _context.Suppliers on rv.SupplierId equals supplier.Id
                                        into SupplierGroup
                                        from s in SupplierGroup.DefaultIfEmpty()
                                        join b in _context.Branches on rv.BranchId equals b.Id
                                        join pm in _context.PaymentMethods on rv.PaymentMethodId equals pm.Id
                                        where rv.BranchId == checkEmployee.BranchId
                                        select new ReceiptVouchersDto()
            {
                Id                = rv.Id,
                Received          = rv.Received,
                BranchName        = b.Name,
                PaymentMethodName = pm.Name,
                ReceivedDate      = rv.ReceivedDate,
                PersonName        = string.IsNullOrEmpty(rv.CustomerId)
                            ? $"Nhà cung cấp {s.Name}"
                            : $"Khách hàng {c.Name}",
                EmployeeName = e.Name
            }
                                        ).GetPagedAsync(pageIndex, pageSize);

            return(new ApiResult <PagedResult <ReceiptVouchersDto> >(HttpStatusCode.OK, receiptVouchers));
        }
 public void AddToSupplierGroups(SupplierGroup supplierGroup)
 {
     base.AddObject("SupplierGroups", supplierGroup);
 }
 public static SupplierGroup CreateSupplierGroup(int ID, string supplierGroupName, bool discontinued, byte[] rowVersion)
 {
     SupplierGroup supplierGroup = new SupplierGroup();
     supplierGroup.Id = ID;
     supplierGroup.SupplierGroupName = supplierGroupName;
     supplierGroup.Discontinued = discontinued;
     supplierGroup.RowVersion = rowVersion;
     return supplierGroup;
 }
Beispiel #26
0
 public void SetUp()
 {
     group = new SupplierGroup(id, name);
 }
Beispiel #27
0
 public static Supplier CreateSupplier(string email, SupplierGroup group)
 {
     return(new Supplier(id, name, address, email, phoneNumber, group));
 }
Beispiel #28
0
        public void UpdateSupplier(int id, string name, string address, string emailAddress, string phoneNumber, SupplierGroup group)
        {
            var supplier = new Supplier(id, name, address, emailAddress, phoneNumber, group);

            supplierDal.Update(supplier);
        }
Beispiel #29
0
        public void UpdateSupplierGroup(int id, string name)
        {
            var supplierGroup = new SupplierGroup(id, name);

            supplierGroupDal.Update(supplierGroup);
        }