Ejemplo n.º 1
0
 public override void SetModel(dynamic entity)
 {
     if (entity is ManufacturersBussinessItemsViewModel)
     {
         ManufacturersBussinessItemsViewModel model = (ManufacturersBussinessItemsViewModel)entity;
         BindingFromModel(model, this);
         ManufacturersName = Manufacturers.Name;
     }
     else
     {
         if (entity is ManufacturersBussinessItems)
         {
             ManufacturersBussinessItems data = (ManufacturersBussinessItems)entity;
             BindingFromModel(data, this);
             ManufacturersName = data.Manufacturers.Name;
         }
         else
         {
             if (entity is SupplierTranscationItem)
             {
                 SupplierTranscationItem data = (SupplierTranscationItem)entity;
                 BindingFromModel(data, this);
                 BindingFromModel(data.ManufacturersBussinessItems, this);
             }
         }
     }
 }
Ejemplo n.º 2
0
        public void QueryDetails()
        {
            Contracts.ManufacturersId = Id;
            Contracts.Query("", Id, IsClient);

            ManufacturersBussinessItems.QueryAsync(Id);

            TranscationRecords.Query(Id);
        }
Ejemplo n.º 3
0
        public override void SetModel(dynamic entity)
        {
            if (!Dispatcher.CheckAccess())
            {
                Dispatcher.Invoke(DispatcherPriority.Background,
                                  new Action <dynamic>(SetModel), entity);
            }
            else
            {
                try
                {
                    if (entity is View_BussinessItemsList)
                    {
                        View_BussinessItemsList data = (View_BussinessItemsList)entity;
                        if (data != null)
                        {
                            BindingFromModel(data, this);
                        }
                    }
                    else
                    {
                        if (entity is ManufacturersBussinessItems)
                        {
                            ManufacturersBussinessItems data = (ManufacturersBussinessItems)entity;
                            BindingFromModel(data, this);
                            this.Manufacturers = data.Manufacturers;

                            if (data.Manufacturers != null)
                            {
                                MaterialCategories = data.MaterialCategories.Name;
                            }
                            if (data.PaymentTypes != null)
                            {
                                PaymentTypeName = data.PaymentTypes.PaymentTypeName;
                            }
                            if (data.TranscationCategories != null)
                            {
                                TranscationCategories = data.TranscationCategories.Name;
                            }
                            if (data.TicketPeriod != null)
                            {
                                TicketPeriod = data.TicketPeriod.Name;
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    setErrortoModel(this, ex);
                }
            }
        }
Ejemplo n.º 4
0
        public override void SaveModel()
        {
            try
            {
                Manufacturers data = new Manufacturers();
                //data.ManufacturersBussinessItems.First().SupplierTranscationItem.First().Projects
                var LoginedUser = controller.GetCurrentLoginUser().Result;

                if (CreateUserId == Guid.Empty)
                {
                    CreateUserId = controller.GetCurrentLoginUser().Result.UserId;
                }

                if (CreateTime.Year < 1754)
                {
                    CreateTime = DateTime.Now;
                }

                CopyToModel(data, this);

                if (ManufacturersBussinessItems != null && ManufacturersBussinessItems.Count > 0)
                {
                    data.ManufacturersBussinessItems = new Collection <ManufacturersBussinessItems>();

                    foreach (var x in ManufacturersBussinessItems)
                    {
                        ManufacturersBussinessItems BItems = new ManufacturersBussinessItems();
                        CopyToModel(BItems, x);
                        BItems.ManufacturersId = Id;
                        BItems.Id = Guid.NewGuid();
                        data.ManufacturersBussinessItems.Add(BItems);
                    }
                }

                if (Contracts != null)
                {
                    if (Contracts.Count > 0)
                    {
                        data.Contacts = new Collection <Entity.Contacts>();

                        foreach (var x in Contracts)
                        {
                            if (x.Id == Guid.Empty)
                            {
                                x.Id = Guid.NewGuid();
                            }



                            if (x.CreateUserId == Guid.Empty)
                            {
                                x.CreateUserId = controller.GetCurrentLoginUser().Result.UserId;
                            }

                            if (x.CreateTime.Year < 1754)
                            {
                                x.CreateTime = CreateTime;
                            }

                            Contacts contact = new Contacts();
                            CopyToModel(contact, x);
                            data.Contacts.Add(contact);
                        }
                    }
                }

                var resultsec = controller.CreateOrUpdate(data);

                if (resultsec.HasError)
                {
                    Errors   = resultsec.Errors;
                    HasError = resultsec.HasError;
                    return;
                }

                Refresh();
            }
            catch (Exception ex)
            {
                setErrortoModel(this, ex);
            }
        }
Ejemplo n.º 5
0
        public override ExecuteResultEntity <Manufacturers> Update(Manufacturers fromModel, bool isLastRecord = true)
        {
            try
            {
                var ManufacturersRepository = RepositoryHelper.GetManufacturersRepository();


                AccessLogRepository accesslog = RepositoryHelper.GetAccessLogRepository(database);

                //var LoginedUser = GetCurrentLoginUser();

                var dbm = (from q in ManufacturersRepository.All()
                           where q.Id == fromModel.Id
                           select q).SingleOrDefault();

                if (dbm != null)
                {
                    CheckAndUpdateValue(fromModel, dbm);

                    var toDel    = dbm.Contacts.Select(s => s.Id).Except(fromModel.Contacts.Select(s => s.Id)).ToList();
                    var toAdd    = fromModel.Contacts.Select(s => s.Id).Except(dbm.Contacts.Select(s => s.Id)).ToList();
                    var samerows = dbm.Contacts.Select(s => s.Id).Intersect(fromModel.Contacts.Select(s => s.Id)).ToList();

                    Stack <Contacts> RemoveStack = new Stack <Contacts>();
                    Stack <Contacts> AddStack    = new Stack <Contacts>();

                    foreach (var delitem in toDel)
                    {
                        RemoveStack.Push(dbm.Contacts.Where(w => w.Id == delitem).Single());
                    }

                    foreach (var additem in toAdd)
                    {
                        AddStack.Push(fromModel.Contacts.Where(w => w.Id == additem).Single());
                    }

                    while (RemoveStack.Count > 0)
                    {
                        dbm.Contacts.Remove(RemoveStack.Pop());
                    }

                    while (AddStack.Count > 0)
                    {
                        dbm.Contacts.Add(AddStack.Pop());
                    }

                    foreach (var sameitem in samerows)
                    {
                        Contacts Source = fromModel.Contacts.Where(w => w.Id == sameitem).Single();
                        Contacts Target = dbm.Contacts.Where(w => w.Id == sameitem).Single();
                        CheckAndUpdateValue(Source, Target);
                    }

                    var repo2 = RepositoryHelper.GetManufacturersBussinessItemsRepository();

                    var toDelBI    = repo2.Where(w => w.ManufacturersId == dbm.Id).Select(s => s.Id).Except(fromModel.ManufacturersBussinessItems.Select(s => s.Id)).ToList();
                    var toAddBI    = fromModel.ManufacturersBussinessItems.Select(s => s.Id).Except(repo2.Where(w => w.ManufacturersId == dbm.Id).Select(s => s.Id)).ToList();
                    var samerowsBI = dbm.ManufacturersBussinessItems.Select(s => s.Id).Intersect(fromModel.ManufacturersBussinessItems.Select(s => s.Id)).ToList();


                    Stack <ManufacturersBussinessItems> RemoveStackBI = new Stack <ManufacturersBussinessItems>();
                    Stack <ManufacturersBussinessItems> AddStackBI    = new Stack <ManufacturersBussinessItems>();

                    bool isuserepo2 = false;

                    foreach (var delitem in toDelBI)
                    {
                        RemoveStackBI.Push(repo2.Where(w => w.Id == delitem).Single());
                    }

                    foreach (var additem in toAddBI)
                    {
                        AddStackBI.Push(fromModel.ManufacturersBussinessItems.Where(w => w.Id == additem).ToList().Single());
                    }

                    while (RemoveStackBI.Count > 0)
                    {
                        isuserepo2 = true;
                        repo2.Delete(RemoveStackBI.Pop());
                        //dbm.ManufacturersBussinessItems.Remove();
                    }

                    while (AddStackBI.Count > 0)
                    {
                        isuserepo2 = true;
                        var en = AddStackBI.Pop();
                        repo2.Add(new ManufacturersBussinessItems()
                        {
                            Id = en.Id,
                            ManufacturersId      = en.ManufacturersId,
                            MaterialCategoriesId = en.MaterialCategoriesId,
                            PaymentTypeId        = en.PaymentTypeId,
                            Name                    = en.Name,
                            TicketPeriodId          = en.TicketPeriodId,
                            TranscationCategoriesId = en.TranscationCategoriesId
                        });
                        //dbm.ManufacturersBussinessItems.Add(AddStackBI.Pop());
                    }

                    if (isuserepo2)
                    {
                        repo2.UnitOfWork.Commit();
                    }

                    foreach (var sameitem in samerowsBI)
                    {
                        ManufacturersBussinessItems Source = fromModel.ManufacturersBussinessItems.Where(w => w.Id == sameitem).Single();
                        ManufacturersBussinessItems Target = dbm.ManufacturersBussinessItems.Where(w => w.Id == sameitem).Single();
                        Target.ManufacturersId      = Source.ManufacturersId;
                        Target.MaterialCategoriesId = Source.MaterialCategoriesId;
                        Target.Name                    = Source.Name;
                        Target.PaymentTypeId           = Source.PaymentTypeId;
                        Target.TicketPeriodId          = Source.TicketPeriodId;
                        Target.TranscationCategoriesId = Source.TranscationCategoriesId;
                    }
                }

                ManufacturersRepository.UnitOfWork.Commit();

                //accesslog.Add(new AccessLog()
                //{
                //    ActionCode = (Byte)ActionCodes.Update,
                //    CreateTime = DateTime.Now,
                //    DataId = dbm.Id.ToString("N"),
                //    Reason = "更新資料",
                //    UserId = LoginedUser.Result.UserId
                //});

                var rtn = Query(w => w.Id == fromModel.Id);
                return(ExecuteResultEntity <Manufacturers> .CreateResultEntity(rtn.Result.SingleOrDefault()));
            }
            catch (Exception ex)
            {
                return(ExecuteResultEntity <Manufacturers> .CreateErrorResultEntity(ex));
            }
        }
Ejemplo n.º 6
0
        public ExecuteResultEntity <ManufacturersBussinessItems> CreateOrUpdateBussinessItems(ManufacturersBussinessItems entity)
        {
            try
            {
                ManufacturersBussinessItemsRepository repo = RepositoryHelper.GetManufacturersBussinessItemsRepository(database);
                var result = from q in repo.All()
                             where q.Id == entity.Id
                             select q;

                if (!result.Any())
                {
                    repo.Add(entity);
                    repo.UnitOfWork.Commit();
                }
                else
                {
                    var dbdata = result.Single();
                    Update(entity.Manufacturers, true);
                }


                repo.UnitOfWork.Commit();

                var rtn = from q in repo.All()
                          where q.Id == entity.Id
                          select q;;

                return(ExecuteResultEntity <ManufacturersBussinessItems> .CreateResultEntity(rtn.SingleOrDefault()));
            }
            catch (Exception ex)
            {
                return(ExecuteResultEntity <ManufacturersBussinessItems> .CreateErrorResultEntity(ex));
            }
        }