示例#1
0
        public async Task UpdateAsync(
            Guid userId,
            CrmTask oldTask,
            CrmTask newTask,
            CancellationToken ct)
        {
            var change = oldTask.UpdateWithLog(userId, x =>
            {
                x.AccountId         = newTask.AccountId;
                x.TypeId            = newTask.TypeId;
                x.StatusId          = newTask.StatusId;
                x.CustomerId        = newTask.CustomerId;
                x.OrderId           = newTask.OrderId;
                x.ResponsibleUserId = newTask.ResponsibleUserId;
                x.Name             = newTask.Name;
                x.Description      = newTask.Description;
                x.Result           = newTask.Result;
                x.Priority         = newTask.Priority;
                x.StartDateTime    = newTask.StartDateTime;
                x.EndDateTime      = newTask.EndDateTime;
                x.DeadLineDateTime = newTask.DeadLineDateTime;
                x.ModifyDateTime   = DateTime.UtcNow;
                x.IsDeleted        = newTask.IsDeleted;
                x.AttributeLinks   = newTask.AttributeLinks.Map(x.Id);
            });

            _storage.Update(oldTask);
            await _storage.AddAsync(change, ct);

            await _storage.SaveChangesAsync(ct);
        }
示例#2
0
        public async Task <Guid> CreateAsync(Guid userId, CrmTask task, CancellationToken ct)
        {
            var newTask = new CrmTask();
            var type    = await _storage.TaskTypes.FirstAsync(t => t.Id == task.TypeId, ct);

            var status = await _storage.TaskStatuses.FirstAsync(t => t.Id == task.StatusId, ct);

            var change = newTask.CreateWithLog(userId, x =>
            {
                x.Id                = task.Id;
                x.AccountId         = task.AccountId;
                x.TypeId            = task.TypeId;
                x.StatusId          = task.StatusId;
                x.CustomerId        = task.CustomerId;
                x.OrderId           = task.OrderId;
                x.CreateUserId      = userId;
                x.ResponsibleUserId = task.ResponsibleUserId;
                x.Name              = task.Name;
                x.Description       = task.Description;
                x.Result            = task.Result;
                x.Priority          = task.Priority;
                x.StartDateTime     = task.StartDateTime;
                x.EndDateTime       = task.EndDateTime;
                x.DeadLineDateTime  = task.DeadLineDateTime;
                x.IsDeleted         = task.IsDeleted;
                x.CreateDateTime    = DateTime.UtcNow;
                x.Type              = type;
                x.Status            = status;
                x.AttributeLinks    = task.AttributeLinks.Map(x.Id);
            });

            var entry = await _storage.AddAsync(newTask, ct);

            await _storage.AddAsync(change, ct);

            await _storage.SaveChangesAsync(ct);

            return(entry.Entity.Id);
        }