Beispiel #1
0
        public async Task <bool> SaveNewAsync <TInput>(TInput input, IPrincipal principal, IDataAccessStrategy <T> savingStrategy = default, params object[] args)
        {
            savingStrategy = savingStrategy ?? dataAccessStrategy;

            savingStrategy.ThrowIfNull(nameof(savingStrategy));

            bool result = false;

            args = args.Concat(input);

            bool canAdd = await savingStrategy.CanAdd(args);

            if (canAdd)
            {
                savingStrategy.PrepareForAdd(args);

                await SaveNewAsync(input); //I tak EF nie obsługuje operacji równoległych

                result = true;
            }

            return(result);
        }
Beispiel #2
0
        public override void PrepareForAdd(params object[] args)
        {
            if (args[0] is TicketSimple ticket)
            {
                if (IsCustomer) //Serwisanci mogą tworzyć zadanie dla wybranego kontrahenta i przedstawiciela
                {
                    ticket.ContrahentId     = ContrahentId;
                    ticket.RepresentativeId = EmployeeId;
                }

                if (!ticket.Files.IsEmpty())
                {
                    ticket.Files.Where(f => fileDataAccessStrategy.CanAdd(ticket, ObjType.Parent, f).Result)
                    .ForEach(f => fileDataAccessStrategy.PrepareForAdd(ticket, ObjType.Parent, f));
                }

                ticket.StatusId = (int)Status.New;

                ticket.ExecutionDate = null;
                ticket.ReceiptDate   = null;
                ticket.OperatorId    = null;
                ticket.Budget        = null;
            }
        }
Beispiel #3
0
        public override void PrepareForAdd(params object[] args)
        {
            if (args[1] is CommentDetails entity &&
                args[0] is Ticket ticket)
            {
                entity.TicketId   = ticket.Id;
                entity.EmployeeId = EmployeeId;

                if (!entity.Files.IsEmpty())
                {
                    entity.Files.Where(f => fileDataAccessStrategy.CanAdd(entity, ObjType.Child, f).Result)
                    .ForEach(f => fileDataAccessStrategy.PrepareForAdd(entity, ObjType.Child, f));
                }

                if ((Status)ticket.StatusId == Status.Clarify && IsCustomer)
                {
                    ticket.StatusId = (int)Status.New;

                    //Jeśli ktoś anulował zadanie w międzyczasie, to nie chcemy było oznaczone jako nowe.
                    //Możliwe jednak, że to nie status został zmieniony. Nie chcemy również, by zadanie tkwiło jako do wyjaśnienia
                    //i wymagane było dodanie kolejnego komentarza przez klienta. Pozostanie więc client wins.
                }
            }
        }
Beispiel #4
0
        public Task SaveFiles(IEnumerable <FileModel> files, IEntity <int> parent, ObjType type)
        {
            var result = Task.CompletedTask;

            if (files.Any())
            {
                files.Where(f => dataAccessStrategy.CanAdd(parent, type, f).Result).ForEach(f => dataAccessStrategy.PrepareForAdd(f));

                result = taskManagerUow.Files.AddFileFromObjectsList(files);
            }

            return(result);
        }